merge the formfield patch from ooo-build
[ooovba.git] / jurt / com / sun / star / lib / uno / environments / remote / NativeThreadPool.java
blob5891714cd78ac0cc321ef1c328ca773bdedff589
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: NativeThreadPool.java,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package com.sun.star.lib.uno.environments.remote;
33 final class NativeThreadPool implements IThreadPool {
34 public NativeThreadPool() {
35 pool = create();
38 public ThreadId getThreadId() {
39 return new ThreadId(threadId());
42 public void attach() {
43 attach(pool);
46 public Object attach(ThreadId id) {
47 attach();
48 return null;
51 public void detach() {
52 detach(pool);
55 public void detach(Object handle, ThreadId id) {
56 detach();
59 public Object enter() throws Throwable {
60 Job job = enter(pool);
61 if (job == null) {
62 throw dispose;
64 return job.execute();
67 public Object enter(Object handle, ThreadId id) throws Throwable {
68 return enter();
71 public void putJob(Job job) {
72 putJob(
73 pool, job.getThreadId().getBytes(), job, job.isRequest(),
74 job.isRequest() && !job.isSynchronous());
77 public void dispose(Throwable throwable) {
78 dispose = throwable;
79 dispose(pool);
82 public void destroy() {
83 destroy(pool);
86 // The native implementation is in
87 // bridges/source/jni_uno/nativethreadpool.cxx:
88 static {
89 System.loadLibrary("java_uno");
91 private static native byte[] threadId();
92 private static native long create();
93 private static native void attach(long pool);
94 private static native Job enter(long pool);
95 private static native void detach(long pool);
96 private static native void putJob(
97 long pool, byte[] threadId, Job job, boolean request, boolean oneWay);
98 private static native void dispose(long pool);
99 private static native void destroy(long pool);
101 private final long pool;
102 private volatile Throwable dispose;