KickJava   Java API By Example, From Geeks To Geeks.

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


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
9 import org.omg.WfBase.*;
10 import org.omg.WorkflowModel.*;
11
12 /**
13 * Required to crate the process.
14 */

15 public class ProcessInstantiatorCORBA extends _WfRequesterImplBase implements ProcessInstantiatorInterface {
16
17    static List instantiators=new ArrayList();
18
19    public static List getInstantiators () {
20       return instantiators;
21    }
22
23    private List performers=new ArrayList();
24
25    /** Create a new WfRequester */
26    public ProcessInstantiatorCORBA() {
27       instantiators.add(this);
28    }
29
30    public void addPerformer (WfProcess pr) {
31       try {
32          performers.add(pr.key());
33       } catch (Exception JavaDoc ex) {}
34    }
35    /**
36     * Gets the number of processes.
37     */

38    public int how_many_performer () throws BaseException {
39       return performers.size();
40    }
41
42    /** Gets an iterator of processes.
43     */

44    public WfProcessIterator get_iterator_performer () throws BaseException {
45       throw new BaseException();
46    }
47
48    /**
49     * A list of processes
50     * @param max_number
51     */

52    public WfProcess[] get_sequence_performer (int max_number) throws BaseException {
53       WfProcess[] processes=new WfProcess[performers.size()];
54       for (int i=0; i<processes.length; i++) {
55          try {
56             processes[i]=SharkClient.getExecAmin().getProcess(performers.get(i).toString());
57          } catch (Exception JavaDoc ex) {}
58       }
59       return processes;
60    }
61
62    /**
63     * Checks if a WfProcess is associated with this requester object
64     * @param member
65     * @return true if the process is found.
66     */

67    public boolean is_member_of_performer (WfProcess member) throws BaseException {
68       return performers.contains(member);
69    }
70
71    /**
72     * Receives notice of event status changes
73     */

74    public void receive_event (WfEventAudit event) throws BaseException, InvalidPerformer {
75       try {
76          String JavaDoc msg="ProcessInstantiator -> Event received:"+
77             " \n\tevent time --> "+new Timestamp JavaDoc(event.time_stamp().time)+
78             " \n\tprocess id --> "+event.process_key()+
79             " \n\tevent type --> "+event.event_type();
80          System.out.println(msg);
81          SharkClient.getServer().doneWith(event);
82       } catch (Throwable JavaDoc ex) {
83       }
84    }
85
86    // Prevents memory leak if client forgets to disconnect
87
public void releaseProcesses() {
88       ExecutionAdministration ea=SharkClient.getExecAmin();
89       Iterator it=performers.iterator();
90       while (it.hasNext()) {
91          String JavaDoc procId=(String JavaDoc)it.next();
92          try {
93             ea.removeProcessRequester(procId);
94          } catch (Exception JavaDoc ex) {
95          }
96       }
97    }
98
99 }
100
Popular Tags