Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/apache/derby/iapi/services/daemon/DaemonFactory.java


1   /*
2   
3      Derby - Class org.apache.derby.iapi.services.daemon.DaemonFactory
4   
5      Copyright 1997, 2004 The Apache Software Foundation or its licensors, as applicable.
6   
7      Licensed under the Apache License, Version 2.0 (the "License");
8      you may not use this file except in compliance with the License.
9      You may obtain a copy of the License at
10  
11        http://www.apache.org/licenses/LICENSE-2.0
12  
13     Unless required by applicable law or agreed to in writing, software
14     distributed under the License is distributed on an "AS IS" BASIS,
15     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16     See the License for the specific language governing permissions and
17     limitations under the License.
18  
19   */
20  
21  package org.apache.derby.iapi.services.daemon;
22  
23  import org.apache.derby.iapi.error.StandardException;
24  
25  /**
26    Daemon Factory can create new DaemonService, which runs on seperate
27    background threads.  One can use these DaemonService to handle background
28    clean up task by implementing Serviceable and subscribing to a DaemonService.
29  
30    A DaemonService is a background worker thread which does asynchronous I/O and
31    general clean up.  It should not be used as a general worker thread for
32    parallel execution.  A DaemonService can be subscribe to by many Serviceable
33    objects and a daemon will call that object's performWork from time to
34    time.  These performWork method should be well behaved - in other words,
35    it should not take too long or hog too many resources or deadlock with 
36    anyone else.  And it cannot (should not) error out.
37  
38    The best way to use a daemon is to have an existing DaemonService and subscribe to it.
39    If you can't find an existing one, then make one thusly:
40  
41    DaemonService daemon = DaemonFactory.createNewDaemon();
42  
43    After you have a daemon, you can subscribe to it by
44    int myClientNumber = daemon.subscribe(serviceableObject);
45  
46    and ask it to run performWork for you ASAP by
47    daemon.serviceNow(myClientNumber);
48  
49    Or, for one time service, you can enqueue a Serviceable Object by
50    daemon.enqueue(serviceableObject, true);  - urgent service
51    daemon.enqueue(serviceableObject, false); - non-urgent service
52  
53    @see DaemonService
54    @see Serviceable
55  */
56  public interface DaemonFactory 
57  {
58    /**
59      Create a new DaemonService with the default daemon timer delay.
60  
61      @exception StandardException Standard cloudscape error policy
62     */
63    public DaemonService createNewDaemon(String name) throws StandardException;
64  }