carpooling java code
#1

Are you looking for carpooling java code ?
Type your request / requirement / comment about carpooling java code in to the right box for getting free material and support from us/dedicated premium members...
Its a free service...==>
==>
==>
==>
Dont forget to save this page.>!
Scroll down to see Save button...!
Reply
#2

carpooling java code

package org.ow2.bonita.example.carpool;
15
16 import java.io.File;
17 import java.util.Map;
18 import java.util.Set;
19 import java.util.TreeMap;
20 import java.util.logging.Level;
21 import java.util.logging.Logger;
22
23 import javax.security.auth.login.LoginContext;
24
25 import org.ow2.bonita.facade.ManagementAPI;
26 import org.ow2.bonita.facade.QueryRuntimeAPI;
27 import org.ow2.bonita.facade.RuntimeAPI;
28 import org.ow2.bonita.facade.def.majorElement.ProcessDefinition;
29 import org.ow2.bonita.facade.exception.ActivityNotFoundException;
30 import org.ow2.bonita.facade.exception.InstanceNotFoundException;
31 import org.ow2.bonita.facade.runtime.ActivityBody;
32 import org.ow2.bonita.facade.runtime.ActivityInstance;
33 import org.ow2.bonita.facade.runtime.InstanceState;
34 import org.ow2.bonita.facade.runtime.ProcessInstance;
35 import org.ow2.bonita.facade.uuid.PackageDefinitionUUID;
36 import org.ow2.bonita.facade.uuid.ProcessInstanceUUID;
37 import org.ow2.bonita.util.AccessorUtil;
38 import org.ow2.bonita.util.BonitaConstants;
39 import org.ow2.bonita.util.BonitaException;
40 import org.ow2.bonita.util.BonitaRuntimeException;
41 import org.ow2.bonita.util.Misc;
42 import org.ow2.bonita.util.SimpleCallbackHandler;
43 import org.ow2.bonita.util.StandardCallbackHandler;
44
45
46 public final class More ...Carpool {
47
48 private More ...Carpool() { }
49
50 private static final Logger LOG = Logger.getLogger(Carpool.class.getName());
51 public static final String PROCESS_ID = "carpool";
52 public static final int CANCEL_PLACE_IMMEDIATELY = 1;
53 public static final int CANCEL_PLACE_AFTER_3_WAIT = 2;
54 public static final int CANCEL_REQUEST = 3;
55 public static final int ASSOCIATION = 4;
56
57 private static final long CANCEL_REQUEST_TIME = 5000;
58 private static final long WAIT_REQUEST_TIME = 5000;
59 private static final long WAIT_ANSWER_TIME = 5000;
60
61 private static final String BAR_PREFIX = "-bar=";
62 private static final String MODE_PREFIX = "-mode=";
63
64 private static Map<String, Object> More ...getVariables(final int mode) {
65 if (mode == CANCEL_REQUEST) {
66 return null;
67 } else if (mode == CANCEL_PLACE_IMMEDIATELY) {
68 Map<String, Object> variables = new TreeMap<String, Object>();
69 variables.put("offerTimeout", "yes");
70 return variables;
71 } else if (mode == CANCEL_PLACE_AFTER_3_WAIT) {
72 return null;
73 } else if (mode == ASSOCIATION) {
74 Map<String, Object> variables = new TreeMap<String, Object>();
75 variables.put("requestFound", "yes");
76 variables.put("answerFound", "yes");
77 return variables;
78 }
79 throw new BonitaRuntimeException("Unknown mode : " + mode);
80 }
81
82 private static void More ...waitForActivityExec(String activityId, int execNb, long maxWaitingTime,
83 QueryRuntimeAPI queryRuntimeAPI, ProcessInstanceUUID instanceUUID) throws BonitaException {
84 long start = System.currentTimeMillis();
85 do {
86 try {
87 Set<ActivityInstance<ActivityBody>> activities = queryRuntimeAPI.getActivityInstances(instanceUUID, activityId);
88 if (activities != null && activities.size() == execNb) {
89 break;
90 }
91 sleep(500);
92 } catch (ActivityNotFoundException e) {
93 //nothing : the activity is not yet executed once
94 sleep(500);
95 }
96 } while ((start + maxWaitingTime) > System.currentTimeMillis());
97 }
98
99 private static void More ...sleep(final long millis) {
100 try {
101 Thread.sleep(millis);
102 } catch (InterruptedException e) {
103 throw new BonitaRuntimeException(e);
104 }
105 }
106
107 private static void More ...waitForInstanceEnd(long processingTime, ProcessInstanceUUID instanceUUID,
108 QueryRuntimeAPI queryRuntimeAPI) throws BonitaException {
109 long deadline = System.currentTimeMillis() + processingTime;
110
111 ProcessInstance processInstance = null;
112 while (System.currentTimeMillis() < deadline) {
113 try {
114 processInstance = queryRuntimeAPI.getProcessInstance(instanceUUID);
115 } catch (InstanceNotFoundException infe) {
116 break;
117 }
118 if (InstanceState.FINISHED.equals(processInstance.getInstanceState())) {
119 break;
120 }
121 try {
122 Thread.sleep(1000);
123 } catch (Exception e) {
124 throw new BonitaRuntimeException(e);
125 }
126 processInstance = null;
127 }
128
129 if (processInstance != null && !InstanceState.FINISHED.equals(processInstance.getInstanceState())) {
130 throw new BonitaRuntimeException("Instance is not finished !");
131 }
132 }
133
134 private static void More ...usage(final String[] args) {
135 LOG.severe("Usage: " + Carpool.class + " " + BAR_PREFIX + "<bar file> " + MODE_PREFIX + "<mode>");
136 LOG.severe("Available modes ares : ");
137 LOG.severe(" 1 -> CANCEL_PLACE_IMMEDIATELY");
138 LOG.severe(" 2 -> CANCEL_PLACE_AFTER_3_WAIT");
139 LOG.severe(" 3 -> CANCEL_REQUEST");
140 LOG.severe(" 4 -> ASSOCIATION");
141 LOG.severe("");
142 LOG.severe("Actual args:");
143 if (args == null) {
144 LOG.severe(" args is null");
145 } else {
146 for (String arg : args) {
147 LOG.severe(" arg:" + arg);
148 }
149 }
150 throw new BonitaRuntimeException("Please read the above usage");
151 }
152
153 public static void More ...main(final String[] args) throws Exception {
154
155 if (args == null || args.length != 2) {
156 usage(args);
157 }
158
159 byte[] barFile = null;
160 int mode = 0;
161 for (String arg : args) {
162 if (arg.startsWith(BAR_PREFIX)) {
163 barFile = Misc.getAllContentFrom(new File(arg.substring(BAR_PREFIX.length())));
164 } else if (arg.startsWith(MODE_PREFIX)) {
165 mode = new Integer(arg.substring(MODE_PREFIX.length()));
166 } else {
167 usage(args);
168 }
169 }
170
171 final String loginMode = System.getProperty(BonitaConstants.LOGIN_MODE_PROPERTY);
172 LoginContext loginContext = null;
173 if (loginMode != null && BonitaConstants.LOGIN_MODE_TEST.equals(loginMode)) {
174 loginContext = new LoginContext("Bonita", new SimpleCallbackHandler("john", "bpm"));
175 } else {
176 loginContext = new LoginContext("Bonita", new StandardCallbackHandler());
177 }
178 loginContext.login();
179
180 ProcessInstanceUUID instanceUUID = execute(barFile, mode);
181 cleanPackage(instanceUUID);
182
183 loginContext.logout();
184 if (LOG.isLoggable(Level.INFO)) {
185 LOG.info("\n***** End of Carpool Main. *****\n");
186 }
187 }
188
189 public static ProcessInstanceUUID More ...execute(final byte[] barFile, final int mode) throws BonitaException {
190 //get APIs
191 final RuntimeAPI runtimeAPI = AccessorUtil.getRuntimeAPI();
192 final QueryRuntimeAPI queryRuntimeAPI = AccessorUtil.getQueryRuntimeAPI();
193 final ManagementAPI managementAPI = AccessorUtil.getManagementAPI();
194
195 //deployment
196 final ProcessDefinition process = managementAPI.deployBar(barFile).get(PROCESS_ID);
197 final PackageDefinitionUUID packageUUID = process.getPackageDefinitionUUID();
198 Misc.badStateIfNull(packageUUID, "packageUUID is null in process : " + process.getProcessId());
199
200 //instantiation
201 final ProcessInstanceUUID instanceUUID = runtimeAPI.instantiateProcess(process.getUUID(), getVariables(mode));
202
203 long processingTime = 10000;
204 if (mode == CANCEL_REQUEST) {
205 waitForActivityExec("WaitRequest", 2, WAIT_REQUEST_TIME * 3, queryRuntimeAPI, instanceUUID);
206 runtimeAPI.setProcessInstanceVariable(instanceUUID, "requestFound", "yes");
207 waitForActivityExec("WaitAnswer", 1, WAIT_ANSWER_TIME * 2, queryRuntimeAPI, instanceUUID);
208 runtimeAPI.setProcessInstanceVariable(instanceUUID, "answerTimeout", "yes");
209 processingTime += CANCEL_REQUEST_TIME;
210 } else if (mode == CANCEL_PLACE_AFTER_3_WAIT) {
211 waitForActivityExec("WaitRequest", 3, WAIT_REQUEST_TIME * 4, queryRuntimeAPI, instanceUUID);
212 runtimeAPI.setProcessInstanceVariable(instanceUUID, "offerTimeout", "yes");
213 }
214 waitForInstanceEnd(processingTime, instanceUUID, queryRuntimeAPI);
215
216 return instanceUUID;
217 }
218
219 public static void More ...cleanPackage(ProcessInstanceUUID instanceUUID) throws BonitaException {
220 final ManagementAPI managementAPI = AccessorUtil.getManagementAPI();
221 final QueryRuntimeAPI queryRuntimeAPI = AccessorUtil.getQueryRuntimeAPI();
222 final ProcessInstance instance = queryRuntimeAPI.getProcessInstance(instanceUUID);
223 final PackageDefinitionUUID packageUUID = instance.getPackageDefinitionUUID();
224
225 //undeployment
226 managementAPI.undeploy(packageUUID);
227 //journal + history cleaning
228 managementAPI.deletePackage(packageUUID);
229 }
230
231}
Reply

Important Note..!

If you are not satisfied with above reply ,..Please

ASK HERE

So that we will collect data for you and will made reply to the request....OR try below "QUICK REPLY" box to add a reply to this page
Popular Searches: carpooling project for cse students, carpooling project srs, carpooling uml diagram, i need er diagram in carpooling project, carpooling project ppt, srs of online carpooling system, ppt on carpooling,

[-]
Quick Reply
Message
Type your reply to this message here.

Image Verification
Please enter the text contained within the image into the text box below it. This process is used to prevent automated spam bots.
Image Verification
(case insensitive)

Possibly Related Threads...
Thread Author Replies Views Last Post
  simple java rmi chat application source code 2 19,723 20-07-2018, 12:08 PM
Last Post: Guest
  free download source code for online movie ticket booking in java 2 19,168 15-08-2017, 03:21 PM
Last Post: Morshed
  source code for rsa encryption and decryption in java 2 8,181 29-05-2017, 04:21 PM
Last Post: Meghna Jadhav
  source code for task scheduling using genetic algorithm using java 2 8,692 11-04-2017, 08:31 PM
Last Post: Guest
  source code for suspicious email detection in java Parvesh.2595 2 1,058 23-08-2016, 04:05 PM
Last Post: seminar report asees
  ticket reservation java source code android 3 949 23-08-2016, 10:58 AM
Last Post: Guest
  java netbeans source code employee management system 2 899 21-07-2016, 02:30 PM
Last Post: jaseela123d
  queue management system in hospital in java with source code 2 907 14-07-2016, 02:39 PM
Last Post: seminar report asees
  lsb 1 bit algorithm implementation java source code 2 933 11-07-2016, 04:44 PM
Last Post: dhanabhagya
  download source code for mobile based attendance system in java 1 587 02-07-2016, 02:00 PM
Last Post: visalakshik

Forum Jump: