KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > shark > corba > poa > WfLinkingRequesterForCORBA


1 package org.enhydra.shark.corba.poa;
2
3 import java.util.HashMap JavaDoc;
4 import java.util.Map JavaDoc;
5
6 import org.enhydra.shark.api.SharkTransaction;
7 import org.enhydra.shark.corba.poa.Collective;
8 import org.enhydra.shark.corba.poa.SharkCORBAUtilities;
9 import org.omg.CORBA.ORB JavaDoc;
10 import org.omg.WorkflowModel.WfRequester;
11 import org.omg.CORBA.ORB JavaDoc;
12
13 /**
14  * WfRequesterImpl - Workflow Requester implementation
15  */

16 public class WfLinkingRequesterForCORBA implements
17                                        org.enhydra.shark.api.client.wfmodel.WfRequester {
18
19
20
21   // transient private Collective __collective;
22
private ORB JavaDoc orb;
23
24     static ORB JavaDoc the_orb;
25
26    static Map JavaDoc requesters=new HashMap JavaDoc();
27
28    static Map JavaDoc collectives=new HashMap JavaDoc();
29    
30    static boolean ignoreProblematicRequester=true;
31
32     public WfLinkingRequesterForCORBA() {
33
34     }
35
36    public WfLinkingRequesterForCORBA(ORB JavaDoc orb) {
37        this.orb = orb;
38    }
39    
40    public static void setOrb(ORB JavaDoc the_Orb) {
41           the_orb = the_Orb;
42    }
43
44    public static synchronized void setIgnoreProblematicRequesterProcess (boolean ignore) {
45       ignoreProblematicRequester=ignore;
46    }
47    
48    public static synchronized void setCORBARequester (String JavaDoc procId,WfRequester myCORBARequester) {
49       requesters.put(procId, myCORBARequester);
50    }
51
52
53    /*
54    public WfLinkingRequesterForCORBA(ORB orb, Collective toJoin,
55                                      WfRequester myCORBARequester) {
56       // if (WfLinkingRequesterForCORBA.myServer==null) {
57       // WfLinkingRequesterForCORBA.myServer=server;
58       // }
59       this.orb = orb;
60
61       __collective = toJoin;
62       this.myCORBARequester = myCORBARequester;
63    }
64     */

65    public static synchronized void removeCORBARequester (String JavaDoc procId) {
66       requesters.remove(procId);
67
68    }
69
70    public static WfRequester getCORBARequester(String JavaDoc procId) {
71       return (WfRequester)requesters.get(procId);
72    }
73
74    public static synchronized void addCollective (String JavaDoc pId,Collective c) {
75       collectives.put(pId,c);
76    }
77
78    public static synchronized void emptyCollective (String JavaDoc pId,ORB JavaDoc orb) {
79       Collective c=(Collective)collectives.remove(pId);
80       if (c!=null) {
81          c.__disband(orb);
82       }
83    }
84    
85    /**
86     * Gets the number of processes.
87     */

88    public int how_many_performer() throws org.enhydra.shark.api.client.wfbase.BaseException {
89       throw new org.enhydra.shark.api.client.wfbase.BaseException();
90    }
91
92    public int how_many_performer(SharkTransaction t) throws org.enhydra.shark.api.client.wfbase.BaseException {
93       throw new org.enhydra.shark.api.client.wfbase.BaseException();
94    }
95
96    /**
97     * Gets an iterator of processes.
98     */

99    public org.enhydra.shark.api.client.wfmodel.WfProcessIterator get_iterator_performer() throws org.enhydra.shark.api.client.wfbase.BaseException {
100       throw new org.enhydra.shark.api.client.wfbase.BaseException();
101    }
102
103    public org.enhydra.shark.api.client.wfmodel.WfProcessIterator get_iterator_performer(SharkTransaction t) throws org.enhydra.shark.api.client.wfbase.BaseException {
104       throw new org.enhydra.shark.api.client.wfbase.BaseException();
105    }
106
107    /**
108     * A list of processes
109     *
110     * @return List of WfProcess objects.
111     */

112    public org.enhydra.shark.api.client.wfmodel.WfProcess[] get_sequence_performer(int max_number) throws org.enhydra.shark.api.client.wfbase.BaseException {
113       throw new org.enhydra.shark.api.client.wfbase.BaseException();
114    }
115
116    public org.enhydra.shark.api.client.wfmodel.WfProcess[] get_sequence_performer(SharkTransaction t,
117                                                                                   int max_number) throws org.enhydra.shark.api.client.wfbase.BaseException {
118       throw new org.enhydra.shark.api.client.wfbase.BaseException();
119    }
120
121    /**
122     * Checks if a WfProcess is associated with this requester object
123     *
124     * @return true if the process is found.
125     */

126    public boolean is_member_of_performer(org.enhydra.shark.api.client.wfmodel.WfProcess member) throws org.enhydra.shark.api.client.wfbase.BaseException {
127       throw new org.enhydra.shark.api.client.wfbase.BaseException();
128    }
129
130    public boolean is_member_of_performer(SharkTransaction t,
131                                          org.enhydra.shark.api.client.wfmodel.WfProcess member) throws org.enhydra.shark.api.client.wfbase.BaseException {
132       throw new org.enhydra.shark.api.client.wfbase.BaseException();
133    }
134
135    public void receive_event(org.enhydra.shark.api.client.wfmodel.WfEventAudit event) throws org.enhydra.shark.api.client.wfbase.BaseException,
136                                                                                      org.enhydra.shark.api.client.wfmodel.InvalidPerformer {
137       try {
138
139          WfRequester req=getCORBARequester(event.process_key());
140          if (req!=null) {
141             Collective __collective = new Collective.CollectiveCORBA();
142             WfLinkingRequesterForCORBA.addCollective(event.process_key(),__collective);
143              if (orb == null) orb = the_orb;
144             req.receive_event(SharkCORBAUtilities.makeCORBAEventAudit(__collective,event));
145          } else {
146          }
147
148       } catch (Throwable JavaDoc ex) {}
149    }
150
151    public void receive_event(SharkTransaction t,
152                              org.enhydra.shark.api.client.wfmodel.WfEventAudit event) throws org.enhydra.shark.api.client.wfbase.BaseException,
153                                                                                      org.enhydra.shark.api.client.wfmodel.InvalidPerformer {
154       String JavaDoc procId=null;
155       boolean ne=false;
156       boolean excH=false;
157       try {
158
159          procId=event.process_key();
160          WfRequester req=WfLinkingRequesterForCORBA.getCORBARequester(procId);
161          if (req!=null) {
162             try {
163                ne=req._non_existent();
164             } catch (Exception JavaDoc ex) {
165                ne=true;
166             }
167             if (!ne) {
168                Collective __collective = new Collective.CollectiveCORBA();
169                WfLinkingRequesterForCORBA.addCollective(procId,__collective);
170                 if (orb == null) orb = the_orb;
171                req.receive_event(SharkCORBAUtilities.makeCORBAEventAudit(__collective,event));
172                System.out.println("External requester for process "+procId+" notified.");
173             } else {
174                String JavaDoc msg="External CORBA requester for process "+procId+" can't be found due to some network problem or client application shutdown";
175                if (ignoreProblematicRequester) {
176                   msg+=" - it'll be further ignored!";
177                } else {
178                   msg+="!";
179                }
180                System.out.println(msg);
181             }
182          } else {
183             String JavaDoc msg="Can't find CORBA external requester for process "+procId+". It might be caused by shark CORBA server shutdown, shark cluster usage,...";
184             if (ignoreProblematicRequester) {
185                msg+=" or because shark CORBA setup to ignore requester notification if some problem previously occured.";
186             }
187             System.out.println(msg);
188          }
189       } catch (Throwable JavaDoc ex) {
190          String JavaDoc msg="Problem accessing CORBA external requester for process "+procId+". Problem could be caused by some network problem or some problem in the implementation of requester's code.";
191          if (ignoreProblematicRequester) {
192             msg+=" - it'll be further ignored!";
193          } else {
194            msg+="!";
195          }
196          System.out.println(msg);
197          excH=true;
198       }
199       if (ignoreProblematicRequester && (ne || excH)) {
200          WfLinkingRequesterForCORBA.removeCORBARequester(procId);
201       }
202
203    }
204
205
206 }
207
208
Popular Tags