1*2be43276SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*2be43276SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*2be43276SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*2be43276SAndrew Rist * distributed with this work for additional information 6*2be43276SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*2be43276SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*2be43276SAndrew Rist * "License"); you may not use this file except in compliance 9*2be43276SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*2be43276SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*2be43276SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*2be43276SAndrew Rist * software distributed under the License is distributed on an 15*2be43276SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*2be43276SAndrew Rist * KIND, either express or implied. See the License for the 17*2be43276SAndrew Rist * specific language governing permissions and limitations 18*2be43276SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*2be43276SAndrew Rist *************************************************************/ 21*2be43276SAndrew Rist 22*2be43276SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir package com.sun.star.lib.uno.environments.remote; 25cdf0e10cSrcweir 26cdf0e10cSrcweir final class NativeThreadPool implements IThreadPool { NativeThreadPool()27cdf0e10cSrcweir public NativeThreadPool() { 28cdf0e10cSrcweir pool = create(); 29cdf0e10cSrcweir } 30cdf0e10cSrcweir getThreadId()31cdf0e10cSrcweir public ThreadId getThreadId() { 32cdf0e10cSrcweir return new ThreadId(threadId()); 33cdf0e10cSrcweir } 34cdf0e10cSrcweir attach()35cdf0e10cSrcweir public void attach() { 36cdf0e10cSrcweir attach(pool); 37cdf0e10cSrcweir } 38cdf0e10cSrcweir attach(ThreadId id)39cdf0e10cSrcweir public Object attach(ThreadId id) { 40cdf0e10cSrcweir attach(); 41cdf0e10cSrcweir return null; 42cdf0e10cSrcweir } 43cdf0e10cSrcweir detach()44cdf0e10cSrcweir public void detach() { 45cdf0e10cSrcweir detach(pool); 46cdf0e10cSrcweir } 47cdf0e10cSrcweir detach(Object handle, ThreadId id)48cdf0e10cSrcweir public void detach(Object handle, ThreadId id) { 49cdf0e10cSrcweir detach(); 50cdf0e10cSrcweir } 51cdf0e10cSrcweir enter()52cdf0e10cSrcweir public Object enter() throws Throwable { 53cdf0e10cSrcweir Job job = enter(pool); 54cdf0e10cSrcweir if (job == null) { 55cdf0e10cSrcweir throw dispose; 56cdf0e10cSrcweir } 57cdf0e10cSrcweir return job.execute(); 58cdf0e10cSrcweir } 59cdf0e10cSrcweir enter(Object handle, ThreadId id)60cdf0e10cSrcweir public Object enter(Object handle, ThreadId id) throws Throwable { 61cdf0e10cSrcweir return enter(); 62cdf0e10cSrcweir } 63cdf0e10cSrcweir putJob(Job job)64cdf0e10cSrcweir public void putJob(Job job) { 65cdf0e10cSrcweir putJob( 66cdf0e10cSrcweir pool, job.getThreadId().getBytes(), job, job.isRequest(), 67cdf0e10cSrcweir job.isRequest() && !job.isSynchronous()); 68cdf0e10cSrcweir } 69cdf0e10cSrcweir dispose(Throwable throwable)70cdf0e10cSrcweir public void dispose(Throwable throwable) { 71cdf0e10cSrcweir dispose = throwable; 72cdf0e10cSrcweir dispose(pool); 73cdf0e10cSrcweir } 74cdf0e10cSrcweir destroy()75cdf0e10cSrcweir public void destroy() { 76cdf0e10cSrcweir destroy(pool); 77cdf0e10cSrcweir } 78cdf0e10cSrcweir 79cdf0e10cSrcweir // The native implementation is in 80cdf0e10cSrcweir // bridges/source/jni_uno/nativethreadpool.cxx: 81cdf0e10cSrcweir static { 82cdf0e10cSrcweir System.loadLibrary("java_uno"); 83cdf0e10cSrcweir } threadId()84cdf0e10cSrcweir private static native byte[] threadId(); create()85cdf0e10cSrcweir private static native long create(); attach(long pool)86cdf0e10cSrcweir private static native void attach(long pool); enter(long pool)87cdf0e10cSrcweir private static native Job enter(long pool); detach(long pool)88cdf0e10cSrcweir private static native void detach(long pool); putJob( long pool, byte[] threadId, Job job, boolean request, boolean oneWay)89cdf0e10cSrcweir private static native void putJob( 90cdf0e10cSrcweir long pool, byte[] threadId, Job job, boolean request, boolean oneWay); dispose(long pool)91cdf0e10cSrcweir private static native void dispose(long pool); destroy(long pool)92cdf0e10cSrcweir private static native void destroy(long pool); 93cdf0e10cSrcweir 94cdf0e10cSrcweir private final long pool; 95cdf0e10cSrcweir private volatile Throwable dispose; 96cdf0e10cSrcweir } 97