bump product version to 5.0.4.1
[LibreOffice.git] / jurt / com / sun / star / lib / uno / environments / remote / NativeThreadPool.java
blob31e7855e98d46f8008e4ae78327181f53e144b18
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package com.sun.star.lib.uno.environments.remote;
21 final class NativeThreadPool implements IThreadPool {
22 public NativeThreadPool() {
23 pool = create();
26 public ThreadId getThreadId() {
27 return new ThreadId(threadId());
30 public void attach() {
31 attach(pool);
34 public Object attach(ThreadId id) {
35 attach();
36 return null;
39 public void detach() {
40 detach(pool);
43 public void detach(Object handle, ThreadId id) {
44 detach();
47 public Object enter() throws Throwable {
48 Job job = enter(pool);
49 if (job == null) {
50 throw dispose;
52 return job.execute();
55 public Object enter(Object handle, ThreadId id) throws Throwable {
56 return enter();
59 public void putJob(Job job) {
60 putJob(
61 pool, job.getThreadId().getBytes(), job, job.isRequest(),
62 job.isRequest() && !job.isSynchronous());
65 public void dispose(Throwable throwable) {
66 dispose = throwable;
67 dispose(pool);
70 public void destroy() {
71 destroy(pool);
74 // The native implementation is in
75 // bridges/source/jni_uno/nativethreadpool.cxx:
76 static {
77 System.loadLibrary("java_uno");
79 private static native byte[] threadId();
80 private static native long create();
81 private static native void attach(long pool);
82 private static native Job enter(long pool);
83 private static native void detach(long pool);
84 private static native void putJob(
85 long pool, byte[] threadId, Job job, boolean request, boolean oneWay);
86 private static native void dispose(long pool);
87 private static native void destroy(long pool);
89 private final long pool;
90 private volatile Throwable dispose;