@Override public synchronized void start() throws Exception { if ((getWrapped() == null) || getWrapped().isShutdown()) { setWrapped(wrap(createExecutorService(getCorePoolSize()))); } super.start(); }
/** * Creates a new JDK executor service that will be wrapped. By default it * calls {@link Executors#newCachedThreadPool(ThreadFactory)}, passing the * result of {@link #createThreadFactory()} as a parameter. * * * @return A new JDK executor service. */ protected ExecutorService createExecutorService() { return Executors.newCachedThreadPool(createThreadFactory()); }
/** * Initiates an orderly shutdown in which previously submitted tasks are * executed, but no new tasks will be accepted. */ public void shutdown() { if (isShutdownAllowed() && (getWrapped() != null)) { getWrapped().shutdown(); } }
/** * Constructor. */ public TaskService() { this.shutdownAllowed = false; setWrapped(wrap(createExecutorService())); }
/** * Executes the given command asynchronously. * * @param command * The command to execute. */ public void execute(Runnable command) { startIfNeeded(); getWrapped().execute(command); }
/** * Returns true if this executor has been shut down. * * @return True if this executor has been shut down. */ public boolean isShutdown() { return (getWrapped() == null) || getWrapped().isShutdown(); }
/** * Constructor. * * @param context * The context to use based on parent component context. This * context should be created using the * {@link Context#createChildContext()} method to ensure a proper * isolation with the other applications. */ @SuppressWarnings("deprecation") public Application(Context context) { super(context); if (Engine.getInstance() != null) { this.helper = Engine.getInstance().createHelper(this); } this.name = null; this.description = null; this.author = null; this.owner = null; this.root = null; this.connectorService = new ConnectorService(); this.converterService = new org.restlet.service.ConverterService(); this.decoderService = new DecoderService(); this.metadataService = new MetadataService(); this.rangeService = new RangeService(); this.statusService = new StatusService(); this.taskService = new TaskService(); this.tunnelService = new TunnelService(true, true); }
getTaskService().start();
/** * Returns a reader from a writer representation.Internally, it uses a * writer thread and a pipe stream. * * @param representation * The representation to read from. * @return The character reader. * @throws IOException */ public static Reader getReader(final WriterRepresentation representation) throws IOException { final PipedWriter pipedWriter = new PipedWriter(); final PipedReader pipedReader = new PipedReader(pipedWriter); final Application application = Application.getCurrent(); // Gets a thread that will handle the task of continuously // writing the representation into the input side of the pipe application.getTaskService().execute(new Runnable() { public void run() { try { representation.write(pipedWriter); pipedWriter.close(); } catch (IOException ioe) { Context.getCurrentLogger().log(Level.FINE, "Error while writing to the piped reader.", ioe); } } }); return pipedReader; }
/** * * @param task * The task to submit. * @return A Future representing pending completion of the task, and whose * get() method will return the given result upon completion. */ public Future<?> submit(Runnable task) { startIfNeeded(); return getWrapped().submit(task); }
/** * Returns true if this executor has been shut down. * * @return True if this executor has been shut down. */ public boolean isShutdown() { return getWrapped().isShutdown(); }
/** * Constructor. */ public Component() { super(); this.hosts = new CopyOnWriteArrayList<VirtualHost>(); this.clients = new ClientList(null); this.servers = new ServerList(null, this); this.realms = new CopyOnWriteArrayList<Realm>(); this.services = new ServiceList(getContext()); if (Engine.getInstance() != null) { // To be done before setting the helper... this.services.add(new org.restlet.service.TaskService()); this.helper = new ComponentHelper(this); Context childContext = getContext().createChildContext(); this.defaultHost = new VirtualHost(childContext); this.internalRouter = new InternalRouter(childContext); this.services.add(new LogService()); getLogService().setContext(childContext); this.services.add(new StatusService()); getStatusService().setContext(childContext); this.clients.setContext(childContext); this.servers.setContext(childContext); } }
/** * Returns a readable byte channel based on the given representation's * content and its write(WritableByteChannel) method. Internally, it uses a * writer thread and a pipe channel. * * @param representation * the representation to get the {@link OutputStream} from. * @return A readable byte channel. * @throws IOException */ public static ReadableByteChannel getChannel( final Representation representation) throws IOException { final Pipe pipe = Pipe.open(); final Application application = Application.getCurrent(); // Get a thread that will handle the task of continuously // writing the representation into the input side of the pipe application.getTaskService().execute(new Runnable() { public void run() { try { final WritableByteChannel wbc = pipe.sink(); representation.write(wbc); wbc.close(); } catch (IOException ioe) { Context.getCurrentLogger().log(Level.FINE, "Error while writing to the piped channel.", ioe); } } }); return pipe.source(); }
@Override public synchronized void start() throws Exception { if (getWrapped().isShutdown()) { setWrapped(wrap(createExecutorService())); } super.start(); }
/** * * @param task * The task to submit. * @param result * The result to return. * @return A Future representing pending completion of the task, and whose * get() method will return the given result upon completion. */ public <T> Future<T> submit(Runnable task, T result) { startIfNeeded(); return getWrapped().submit(task, result); }
/** * Initiates an orderly shutdown in which previously submitted tasks are * executed, but no new tasks will be accepted. */ public void shutdown() { if (isShutdownAllowed()) { getWrapped().shutdown(); } }
/** * * @param task * The task to submit. * @param result * The result to return. * @return A Future representing pending completion of the task, and whose * get() method will return the given result upon completion. */ public <T> Future<T> submit(Runnable task, T result) { return getWrapped().submit(task, result); }
this.services.add(metadataService); this.services.add(new org.restlet.service.TaskService(false));
/** * Creates a new JDK executor service that will be wrapped. By default it * calls {@link Executors#newCachedThreadPool(ThreadFactory)}, passing the * result of {@link #createThreadFactory()} as a parameter. * * @param corePoolSize * The core pool size defining the maximum number of threads. * @return A new JDK executor service. */ protected ScheduledExecutorService createExecutorService(int corePoolSize) { return Executors.newScheduledThreadPool(corePoolSize, createThreadFactory()); }