001: package org.enhydra.shark.corba;
002:
003: import java.util.HashMap;
004: import java.util.Map;
005:
006: import javax.transaction.UserTransaction;
007:
008: import org.omg.CORBA.ORB;
009: import org.omg.WorkflowModel.WfRequester;
010:
011: /**
012: * WfRequesterImpl - Workflow Requester implementation
013: */
014: public class WfLinkingRequesterForCORBA implements
015: org.enhydra.shark.api.client.wfmodel.WfRequester {
016:
017: static Map requesters = new HashMap();
018:
019: static Map collectives = new HashMap();
020:
021: static boolean ignoreProblematicRequester = true;
022:
023: public WfLinkingRequesterForCORBA() {
024: }
025:
026: public static synchronized void setIgnoreProblematicRequesterProcess(
027: boolean ignore) {
028: ignoreProblematicRequester = ignore;
029: }
030:
031: public static synchronized void setCORBARequester(String procId,
032: WfRequester myCORBARequester) {
033: requesters.put(procId, myCORBARequester);
034: }
035:
036: public static synchronized void removeCORBARequester(String procId) {
037: requesters.remove(procId);
038: }
039:
040: public static WfRequester getCORBARequester(String procId) {
041: return (WfRequester) requesters.get(procId);
042: }
043:
044: public static synchronized void addCollective(String pId,
045: Collective c) {
046: collectives.put(pId, c);
047: }
048:
049: public static synchronized void emptyCollective(String pId, ORB orb) {
050: Collective c = (Collective) collectives.remove(pId);
051: if (c != null) {
052: c.__disband(orb);
053: }
054: }
055:
056: /**
057: * Gets the number of processes.
058: */
059: public int how_many_performer()
060: throws org.enhydra.shark.api.client.wfbase.BaseException {
061: throw new org.enhydra.shark.api.client.wfbase.BaseException();
062: }
063:
064: /**
065: * Gets an iterator of processes.
066: */
067: public org.enhydra.shark.api.client.wfmodel.WfProcessIterator get_iterator_performer()
068: throws org.enhydra.shark.api.client.wfbase.BaseException {
069: throw new org.enhydra.shark.api.client.wfbase.BaseException();
070: }
071:
072: /**
073: * A list of processes
074: *
075: * @return List of WfProcess objects.
076: */
077: public org.enhydra.shark.api.client.wfmodel.WfProcess[] get_sequence_performer(
078: int max_number)
079: throws org.enhydra.shark.api.client.wfbase.BaseException {
080: throw new org.enhydra.shark.api.client.wfbase.BaseException();
081: }
082:
083: /**
084: * Checks if a WfProcess is associated with this requester object
085: *
086: * @return true if the process is found.
087: */
088: public boolean is_member_of_performer(
089: org.enhydra.shark.api.client.wfmodel.WfProcess member)
090: throws org.enhydra.shark.api.client.wfbase.BaseException {
091: throw new org.enhydra.shark.api.client.wfbase.BaseException();
092: }
093:
094: public void receive_event(
095: org.enhydra.shark.api.client.wfmodel.WfEventAudit event)
096: throws org.enhydra.shark.api.client.wfbase.BaseException,
097: org.enhydra.shark.api.client.wfmodel.InvalidPerformer {
098: String procId = null;
099: boolean ne = false;
100: boolean excH = false;
101: UserTransaction ut = null;
102: boolean e = SharkCORBAServer.doesTransactionExist();
103: try {
104: ut = SharkCORBAUtilities.beginTransaction(e);
105: procId = event.process_key();
106: WfRequester req = WfLinkingRequesterForCORBA
107: .getCORBARequester(procId);
108: if (req != null) {
109: try {
110: ne = req._non_existent();
111: } catch (Exception ex) {
112: ne = true;
113: }
114: if (!ne) {
115: Collective __collective = new Collective.CollectiveCORBA();
116: WfLinkingRequesterForCORBA.addCollective(procId,
117: __collective);
118: req.receive_event(SharkCORBAUtilities
119: .makeCORBAEventAudit(__collective, event));
120: System.out
121: .println("External requester for process "
122: + procId + " notified.");
123: } else {
124: String msg = "External CORBA requester for process "
125: + procId
126: + " can't be found due to some network problem or client application shutdown";
127: if (ignoreProblematicRequester) {
128: msg += " - it'll be further ignored!";
129: } else {
130: msg += "!";
131: }
132: System.out.println(msg);
133: }
134: } else {
135: String msg = "Can't find CORBA external requester for process "
136: + procId
137: + ". It might be caused by shark CORBA server shutdown, shark cluster usage,...";
138: if (ignoreProblematicRequester) {
139: msg += " or because shark CORBA setup to ignore requester notification if some problem previously occured.";
140: }
141: System.out.println(msg);
142: }
143: SharkCORBAUtilities.commitTransaction(ut, e);
144: } catch (Throwable ex) {
145: SharkCORBAUtilities.rollbackTransaction(ut, e);
146: String msg = "Problem accessing CORBA external requester for process "
147: + procId
148: + ". Problem could be caused by some network problem or some problem in the implementation of requester's code.";
149: if (ignoreProblematicRequester) {
150: msg += " - it'll be further ignored!";
151: } else {
152: msg += "!";
153: }
154: System.out.println(msg);
155: excH = true;
156: }
157: if (ignoreProblematicRequester && (ne || excH)) {
158: WfLinkingRequesterForCORBA.removeCORBARequester(procId);
159: }
160: }
161:
162: }
|