/* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ package org.apache.tuscany.sca.core.work.impl; import java.security.AccessController; import java.security.PrivilegedAction; import org.apache.tuscany.sca.work.NotificationListener; import org.apache.tuscany.sca.work.WorkScheduler; import org.apache.tuscany.sca.work.WorkSchedulerException; /** * A work scheduler implementation based on a JSR 237 work manager. *
* * This needs a JSR 237 work manager implementation available for scheduling work. Instances can be configured with a * work manager implementation that is injected in. It is the responsibility of the runtime environment to make a work * manager implementation available. For example, if the managed environment supports work manager the runtime can use * the appropriate lookup mechanism to inject the work manager implementation. * * @version $Rev$ $Date$ */ public class DefaultWorkScheduler implements WorkScheduler { /** * Underlying JSR-237 work manager */ private ThreadPoolWorkManager jsr237WorkManager; /** * Initializes the JSR 237 work manager. * * @param jsr237WorkManager JSR 237 work manager. */ public DefaultWorkScheduler() { } private synchronized ThreadPoolWorkManager getWorkManager() { if (jsr237WorkManager != null) { return jsr237WorkManager; } // try { // InitialContext ctx = new InitialContext(); // jsr237WorkManager = (ThreadPoolWorkManager)ctx.lookup("java:comp/env/wm/TuscanyWorkManager"); // } catch (Throwable e) { // // ignore // } if (jsr237WorkManager == null) { jsr237WorkManager = new ThreadPoolWorkManager(10); } return jsr237WorkManager; } /** * Schedules a unit of work for future execution. The notification listener is used to register interest in * callbacks regarding the status of the work. * * @param work The unit of work that needs to be asynchronously executed. */ public