KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > shark > corbaclient > workflowadmin > instantiation > ProcessInstantiatorPOA


1 package org.enhydra.shark.corbaclient.workflowadmin.instantiation;
2
3 import java.sql.Timestamp JavaDoc;
4 import java.util.*;
5
6 import org.enhydra.shark.corba.WorkflowService.ExecutionAdministration;
7 import org.enhydra.shark.corbaclient.*;
8 import org.omg.WfBase.*;
9 import org.omg.WorkflowModel.*;
10 import org.omg.CORBA.ORB JavaDoc;
11 import org.omg.CORBA.ORBPackage.InvalidName JavaDoc;
12 import org.omg.PortableServer.POA JavaDoc;
13 import org.omg.PortableServer.POAHelper JavaDoc;
14 import org.omg.PortableServer.POAPackage.ServantNotActive JavaDoc;
15 import org.omg.PortableServer.POAPackage.WrongPolicy JavaDoc;
16 import org.omg.PortableServer.POAPackage.ServantAlreadyActive JavaDoc;
17 import org.omg.PortableServer.POAManagerPackage.AdapterInactive JavaDoc;
18
19 /**
20  * Required to crate the process.
21  */

22 public class ProcessInstantiatorPOA extends WfRequesterPOA implements ProcessInstantiatorInterface {
23     static List instantiators = new ArrayList();
24     static POA JavaDoc rootPOA;
25
26     public static List getInstantiators() {
27         return instantiators;
28     }
29
30     private List performers = new ArrayList();
31
32     /**
33          * Create a new WfRequester
34          */

35     public ProcessInstantiatorPOA() {
36
37
38         try {
39             if (rootPOA == null) rootPOA = POAHelper.narrow(SharkClient.getORB().resolve_initial_references("RootPOA"));
40             rootPOA.activate_object(this);
41         } catch (InvalidName JavaDoc invalidName) {
42             invalidName.printStackTrace();
43         } catch (ServantAlreadyActive JavaDoc servantAlreadyActive) {
44             servantAlreadyActive.printStackTrace();
45         } catch (WrongPolicy JavaDoc wrongPolicy) {
46             wrongPolicy.printStackTrace();
47         }
48         instantiators.add(this);
49
50     }
51
52     public void addPerformer(WfProcess pr) {
53         try {
54             performers.add(pr.key());
55         } catch (Exception JavaDoc ex) {
56             System.err.println("addPerformer: " + ex);
57         }
58     }
59
60     /**
61      * Gets the number of processes.
62      */

63     public int how_many_performer() throws BaseException {
64         return performers.size();
65     }
66
67     /**
68          * Gets an iterator of processes.
69          */

70     public WfProcessIterator get_iterator_performer() throws BaseException {
71         throw new BaseException();
72     }
73
74     /**
75          * A list of processes
76          *
77          * @param max_number
78          */

79     public WfProcess[] get_sequence_performer(int max_number) throws BaseException {
80         WfProcess[] processes = new WfProcess[performers.size()];
81         for (int i = 0; i < processes.length; i++) {
82             try {
83                 processes[i] = SharkClient.getExecAmin().getProcess(performers.get(i).toString());
84             } catch (Exception JavaDoc ex) {
85             }
86         }
87         return processes;
88     }
89
90     /**
91          * Checks if a WfProcess is associated with this requester object
92          *
93          * @param member
94          * @return true if the process is found.
95          */

96     public boolean is_member_of_performer(WfProcess member) throws BaseException {
97         return performers.contains(member);
98     }
99
100     /**
101      * Receives notice of event status changes
102      */

103     public void receive_event(WfEventAudit event) throws BaseException, InvalidPerformer {
104         try {
105             String JavaDoc msg = "ProcessInstantiatorPOA -> Event received:" +
106                     " \n\tevent time --> " + new Timestamp JavaDoc(event.time_stamp().time) +
107                     " \n\tprocess id --> " + event.process_key() +
108                     " \n\tevent type --> " + event.event_type();
109             System.out.println(msg);
110             SharkClient.getServer().doneWith(event);
111         } catch (Throwable JavaDoc ex) {
112         }
113     }
114
115     // Prevents memory leak if client forgets to disconnect
116
public void releaseProcesses() {
117         ExecutionAdministration ea = SharkClient.getExecAmin();
118         Iterator it = performers.iterator();
119         while (it.hasNext()) {
120             String JavaDoc procId = (String JavaDoc) it.next();
121             try {
122                 ea.removeProcessRequester(procId);
123             } catch (Exception JavaDoc ex) {
124             }
125         }
126     }
127
128 }
129
Popular Tags