public static TaskClient newAsyncInstance(Properties properties, String connectorId) { TaskClient client = null; String defaultPort = null; String strategy = properties.getProperty("jbpm.console.task.service.strategy", DEFAULT_TASK_SERVICE_STRATEGY); if ("Mina".equalsIgnoreCase(strategy)) { if (client == null) { client = new TaskClient( new MinaTaskClientConnector( connectorId, new MinaTaskClientHandler( SystemEventListenerFactory.getSystemEventListener()))); defaultPort = "9123"; } } else { throw new IllegalArgumentException("Unknown TaskClient type was specified: " + strategy); } String host = properties.getProperty("jbpm.console.task.service.host", DEFAULT_IP_ADDRESS); String port = properties.getProperty("jbpm.console.task.service.port", defaultPort); boolean connected = client.connect(host, Integer.parseInt(port)); if (!connected) { throw new IllegalArgumentException( "Could not connect task client " + strategy + "(" + host + ":" + port + ")"); } return client; }
@Test public void test1() throws Exception { SystemEventListener l = SystemEventListenerFactory.getSystemEventListener(); MessageReceiverHandler accHandler = new MessageReceiverHandler() { private String id; private AtomicLong counter = new AtomicLong(); public void messageReceived(Conversation conversation, Message msgIn) { conversation.respond("echo: " + msgIn.getBody()); } }; Acceptor acc = new MinaAcceptor(); acc.open(new InetSocketAddress("127.0.0.1", 8000), accHandler, l); ConversationManager cm = new ConversationManagerImpl(new GridImpl("peer"), l); Conversation cv = cm.startConversation("s1", new InetSocketAddress("127.0.0.1", 8000), "r1"); BlockingMessageResponseHandler blockHandler = new BlockingMessageResponseHandler(); cv.sendMessage("hello", blockHandler); Message msg = blockHandler.getMessage(5000); System.out.println(msg.getBody()); cv.endConversation(); if (acc.isOpen()) { acc.close(); } assertEquals(false, acc.isOpen()); }
public static final void main(String[] args) throws Exception { // load up the knowledge base KnowledgeBase kbase = readKnowledgeBase(); StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession(); // setup task client to use running BRMS server task client. TaskClient client = new TaskClient( new HornetQTaskClientConnector( "taskClient" + UUID.randomUUID(), new HornetQTaskClientHandler(SystemEventListenerFactory.getSystemEventListener()))); client.connect("127.0.0.1", 5153); // setup task client to use running BRMS server task client. CommandBasedHornetQWSHumanTaskHandler handler = new CommandBasedHornetQWSHumanTaskHandler(ksession); handler.setClient(client); // register work items. ksession.getWorkItemManager().registerWorkItemHandler("Log", new SystemOutWorkItemHandler()); ksession.getWorkItemManager().registerWorkItemHandler("Email", new SystemOutWorkItemHandler()); ksession.getWorkItemManager().registerWorkItemHandler("Human Task", handler); // setup our input request for processing. Map<String, Object> params = new HashMap<String, Object>(); params.put("employee", "erics"); params.put("reason", "Amazing demos for JBoss World"); // start a new process instance // start a new process instance System.out.println("Starting Rewards process testing..."); ksession.startProcess("org.jbpm.approval.rewards", params); System.out.println("Rewards process testing started and at first Human Task..."); }
@Override protected void setUp() throws Exception { super.setUp(); ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false"); this.context = EasyMock.createMock(Context.class); EasyMock.expect(context.lookup("ConnectionFactory")).andReturn(factory).anyTimes(); EasyMock.replay(context); Properties serverProperties = new Properties(); serverProperties.setProperty("JMSTaskServer.connectionFactory", "ConnectionFactory"); serverProperties.setProperty("JMSTaskServer.transacted", "true"); serverProperties.setProperty("JMSTaskServer.acknowledgeMode", "AUTO_ACKNOWLEDGE"); serverProperties.setProperty("JMSTaskServer.queueName", "tasksQueue"); serverProperties.setProperty("JMSTaskServer.responseQueueName", "tasksResponseQueue"); server = new JMSTaskServer(taskService, serverProperties, context); Thread thread = new Thread(server); thread.start(); System.out.println("Waiting for the JMS Task Server to come up"); while (!server.isRunning()) { System.out.print("."); Thread.sleep(50); } Properties clientProperties = new Properties(); clientProperties.setProperty("JMSTaskClient.connectionFactory", "ConnectionFactory"); clientProperties.setProperty("JMSTaskClient.transactedQueue", "true"); clientProperties.setProperty("JMSTaskClient.acknowledgeMode", "AUTO_ACKNOWLEDGE"); clientProperties.setProperty("JMSTaskClient.queueName", "tasksQueue"); clientProperties.setProperty("JMSTaskClient.responseQueueName", "tasksResponseQueue"); client = new TaskClient( new JMSTaskClientConnector( "client 1", new JMSTaskClientHandler(SystemEventListenerFactory.getSystemEventListener()), clientProperties, context)); client.connect(); MockUserInfo userInfo = new MockUserInfo(); userInfo.getEmails().put(users.get("tony"), "*****@*****.**"); userInfo.getEmails().put(users.get("steve"), "*****@*****.**"); userInfo.getLanguages().put(users.get("tony"), "en-UK"); userInfo.getLanguages().put(users.get("steve"), "en-UK"); taskService.setUserinfo(userInfo); }
protected void setUp() throws Exception { Properties conf = new Properties(); conf.setProperty("mail.smtp.host", "localhost"); conf.setProperty("mail.smtp.port", "2345"); conf.setProperty("from", "*****@*****.**"); conf.setProperty("replyTo", "*****@*****.**"); conf.setProperty("defaultLanguage", "en-UK"); SendIcal.initInstance(conf); Properties dsProps = loadDataSourceProperties(); String txType = dsProps.getProperty("txType", "RESOURCE_LOCAL"); if ("RESOURCE_LOCAL".equals(txType)) { useJTA = false; } else if ("JTA".equals(txType)) { useJTA = true; } if (useJTA) { pds = new PoolingDataSource(); pds.setUniqueName("jdbc/taskDS"); pds.setClassName(dsProps.getProperty("className")); pds.setMaxPoolSize(Integer.parseInt(dsProps.getProperty("maxPoolSize"))); pds.setAllowLocalTransactions( Boolean.parseBoolean(dsProps.getProperty("allowLocalTransactions"))); for (String propertyName : new String[] {"user", "password"}) { pds.getDriverProperties().put(propertyName, dsProps.getProperty(propertyName)); } setDatabaseSpecificDataSourceProperties(pds, dsProps); pds.init(); } // Use persistence.xml configuration emf = createEntityManagerFactory(); taskService = new TaskService(emf, SystemEventListenerFactory.getSystemEventListener()); MockUserInfo userInfo = new MockUserInfo(); taskService.setUserinfo(userInfo); users = fillUsersOrGroups("LoadUsers.mvel"); groups = fillUsersOrGroups("LoadGroups.mvel"); taskService.addUsersAndGroups(users, groups); disableUserGroupCallback(); logger = LoggerFactory.getLogger(getClass()); taskSession = taskService.createSession(); }
public static void main(String[] args) { EntityManagerFactory emf = Persistence.createEntityManagerFactory("org.jbpm.task"); TaskService taskService = new TaskService(emf, SystemEventListenerFactory.getSystemEventListener()); TaskServiceSession taskSession = taskService.createSession(); // Add users Map vars = new HashMap(); InputStream usersin = DemoTaskService.class.getResourceAsStream("LoadUsers.mvel"); if (usersin != null) { Reader reader = new InputStreamReader(usersin); @SuppressWarnings("unchecked") Map<String, User> users = (Map<String, User>) TaskService.eval(reader, vars); for (User user : users.values()) { taskSession.addUser(user); } } InputStream groupsin = DemoTaskService.class.getResourceAsStream("LoadGroups.mvel"); if (groupsin != null) { Reader reader = new InputStreamReader(groupsin); @SuppressWarnings("unchecked") Map<String, Group> groups = (Map<String, Group>) TaskService.eval(reader, vars); for (Group group : groups.values()) { taskSession.addGroup(group); } } // try to get the usergroup callback properties InputStream usergroupsin = DemoTaskService.class.getResourceAsStream("jbpm.usergroup.callback.properties"); if (usergroupsin != null) { Properties callbackproperties = new Properties(); try { // Properties.load(Reader) is a JDK 6 method callbackproperties.load(usergroupsin); UserGroupCallbackManager.getInstance().setCallbackFromProperties(callbackproperties); System.out.println("Task service registered usergroup callback ..."); } catch (Exception e) { System.out.println("Task service unable to register usergroup callback ..."); } } // start server MinaTaskServer server = new MinaTaskServer(taskService); Thread thread = new Thread(server); thread.start(); taskSession.dispose(); System.out.println("Task service started correctly!"); System.out.println("Task service running ..."); }
protected void onSetUp() throws Exception { ServiceReference kbuilderRef = bundleContext.getServiceReference(KnowledgeBuilderFactoryService.class.getName()); Thread.currentThread() .setContextClassLoader(bundleContext.getService(kbuilderRef).getClass().getClassLoader()); // -- Properties conf = new Properties(); conf.setProperty("mail.smtp.host", "localhost"); conf.setProperty("mail.smtp.port", "2345"); conf.setProperty("from", "*****@*****.**"); conf.setProperty("replyTo", "*****@*****.**"); conf.setProperty("defaultLanguage", "en-UK"); SendIcal.initInstance(conf); if (useJTA) { ds = new PoolingDataSource(); ds.setUniqueName("jdbc/taskDS"); ds.setClassName("bitronix.tm.resource.jdbc.lrc.LrcXADataSource"); ds.setMaxPoolSize(3); ds.setAllowLocalTransactions(true); ds.getDriverProperties().put("user", "sa"); ds.getDriverProperties().put("password", "sasa"); ds.getDriverProperties().put("url", "jdbc:h2:mem:taskDb"); ds.getDriverProperties().put("driverClassName", "org.h2.Driver"); ds.init(); } // Use persistence.xml configuration emfTaskJPA = createEntityManagerFactory(); taskService = new TaskService(emfTaskJPA, SystemEventListenerFactory.getSystemEventListener()); MockUserInfo userInfo = new MockUserInfo(); taskService.setUserinfo(userInfo); users = fillUsersOrGroups("LoadUsers.mvel"); groups = fillUsersOrGroups("LoadGroups.mvel"); taskService.addUsersAndGroups(users, groups); disableUserGroupCallback(); logger = LoggerFactory.getLogger(getClass()); taskSession = taskService.createSession(); }
@Override protected void setUp() throws Exception { super.setUp(); ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false"); this.context = EasyMock.createMock(Context.class); EasyMock.expect(context.lookup("ConnectionFactory")).andReturn(factory).anyTimes(); EasyMock.replay(context); Properties serverProperties = new Properties(); serverProperties.setProperty("JMSTaskServer.connectionFactory", "ConnectionFactory"); serverProperties.setProperty("JMSTaskServer.transacted", "true"); serverProperties.setProperty("JMSTaskServer.acknowledgeMode", "AUTO_ACKNOWLEDGE"); serverProperties.setProperty("JMSTaskServer.queueName", "tasksQueue"); serverProperties.setProperty("JMSTaskServer.responseQueueName", "tasksResponseQueue"); server = new JMSTaskServer(taskService, serverProperties, context); Thread thread = new Thread(server); thread.start(); while (!server.isRunning()) { System.out.print("."); Thread.sleep(50); } Properties clientProperties = new Properties(); clientProperties.setProperty("JMSTaskClient.connectionFactory", "ConnectionFactory"); clientProperties.setProperty("JMSTaskClient.transactedQueue", "true"); clientProperties.setProperty("JMSTaskClient.acknowledgeMode", "AUTO_ACKNOWLEDGE"); clientProperties.setProperty("JMSTaskClient.queueName", "tasksQueue"); clientProperties.setProperty("JMSTaskClient.responseQueueName", "tasksResponseQueue"); client = new SyncTaskServiceWrapper( new TaskClient( new JMSTaskClientConnector( "client 1", new JMSTaskClientHandler(SystemEventListenerFactory.getSystemEventListener()), clientProperties, context))); client.connect(); }
private static void setupTaskServer() throws InterruptedException { EntityManagerFactory emf = Persistence.createEntityManagerFactory("org.jbpm.task"); EscalatedDeadlineHandler handler = buildDeadlineHnadler(); TaskService taskService = new TaskService(emf, SystemEventListenerFactory.getSystemEventListener(), handler); // start server TaskServer taskServer = new MinaTaskServer(taskService, 9123); Thread serverThread = new Thread(taskServer); serverThread.start(); Thread.sleep(1000); TaskServiceSession taskSession = taskService.createSession(); taskSession.addUser(new User("john")); taskSession.addUser(new User("mike")); taskSession.addUser(new User("Administrator")); taskSession.dispose(); }
private void runCallBacks() { ScheduledJob item = queue.peek(); long fireTime; while (item != null && ((fireTime = item.getTrigger().hasNextFireTime().getTime()) <= this.timer)) { // remove the head queue.remove(); if (item.getHandle().isCancel()) { // do not call it, do not reschedule it continue; } // updates the trigger item.getTrigger().nextFireTime(); if (item.getTrigger().hasNextFireTime() != null) { // reschedule for the next fire time, if one exists queue.add(item); } // save the current timer because we are going to override to to the job's trigger time long savedTimer = this.timer; try { // set the clock back to the trigger's fire time this.timer = fireTime; // execute the call item.call(); } catch (Exception e) { SystemEventListenerFactory.getSystemEventListener().exception(e); } finally { this.timer = savedTimer; } // get next head item = queue.peek(); } }
public static final void main(String[] args) { try { setupTaskServer(); // load up the knowledge base KnowledgeBase kbase = readKnowledgeBase(); StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession(); KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory.newConsoleLogger(ksession); ksession .getWorkItemManager() .registerWorkItemHandler("Human Task", new CommandBasedWSHumanTaskHandler(ksession)); // start a new process instance Map<String, Object> params = new HashMap<String, Object>(); params.put("userId", "krisv"); params.put("s", "Need a new laptop computer"); ksession.startProcess("UserTask", params); SystemEventListenerFactory.setSystemEventListener(new SystemEventListener()); TaskClient taskClient = new TaskClient( new MinaTaskClientConnector( "MinaConnector", new MinaTaskClientHandler(SystemEventListenerFactory.getSystemEventListener()))); taskClient.connect("127.0.0.1", 9123); Thread.sleep(1000); // sleep to allow notification to be sent for deadline start Thread.sleep(6000); // Assert.assertEquals(4, wiser.getMessages().size()); // Assert.assertEquals("*****@*****.**", // wiser.getMessages().get(0).getEnvelopeReceiver()); // Assert.assertEquals("*****@*****.**", // wiser.getMessages().get(1).getEnvelopeReceiver()); // Assert.assertEquals("Task is ready for mike", // wiser.getMessages().get(0).getMimeMessage().getSubject()); // wait another few seconds to trigger complete deadline Thread.sleep(4000); // Assert.assertEquals(6, wiser.getMessages().size()); // Assert.assertEquals("*****@*****.**", // wiser.getMessages().get(2).getEnvelopeReceiver()); // Assert.assertEquals("*****@*****.**", // wiser.getMessages().get(3).getEnvelopeReceiver()); // Assert.assertEquals("Not completedTask is ready for mike", // wiser.getMessages().get(4).getMimeMessage().getSubject()); BlockingTaskSummaryResponseHandler taskSummaryHandler = new BlockingTaskSummaryResponseHandler(); taskClient.getTasksAssignedAsPotentialOwner("mike", "en-UK", taskSummaryHandler); TaskSummary task1 = taskSummaryHandler.getResults().get(0); BlockingTaskOperationResponseHandler taskOperationHandler = new BlockingTaskOperationResponseHandler(); taskClient.start(task1.getId(), "mike", taskOperationHandler); taskOperationHandler.waitTillDone(1000); taskOperationHandler = new BlockingTaskOperationResponseHandler(); Map<String, Object> results = new HashMap<String, Object>(); results.put("comment", "Agreed, existing laptop needs replacing"); results.put("outcome", "Accept"); ContentData contentData = new ContentData(); contentData.setAccessType(AccessType.Inline); ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutputStream out; try { out = new ObjectOutputStream(bos); out.writeObject(results); out.close(); contentData = new ContentData(); contentData.setContent(bos.toByteArray()); contentData.setAccessType(AccessType.Inline); } catch (IOException e) { e.printStackTrace(); } taskClient.complete(task1.getId(), "mike", contentData, taskOperationHandler); taskOperationHandler.waitTillDone(1000); Thread.sleep(1000); logger.close(); } catch (Throwable t) { t.printStackTrace(); } wiser.stop(); System.exit(0); }
@Test public void test1() { Map<String, GridServiceDescription> coreServicesMap = new HashMap< String, GridServiceDescription>(); // Hazelcast.newHazelcastInstance( null ).getMap( // CoreServicesLookup.class.getName() ); SystemEventListener l = SystemEventListenerFactory.getSystemEventListener(); GridImpl grid1 = new GridImpl(new ConcurrentHashMap<String, Object>()); GridPeerConfiguration conf = new GridPeerConfiguration(); GridPeerServiceConfiguration coreSeviceConf = new CoreServicesLookupConfiguration(coreServicesMap); conf.addConfiguration(coreSeviceConf); MultiplexSocketServiceCongifuration socketConf = new MultiplexSocketServiceCongifuration( new MultiplexSocketServerImpl("127.0.0.1", new MinaAcceptorFactoryService(), l, grid1)); conf.addConfiguration(socketConf); WhitePagesLocalConfiguration wplConf = new WhitePagesLocalConfiguration(); wplConf.setWhitePages( new JpaWhitePages(Persistence.createEntityManagerFactory("org.drools.grid"))); conf.addConfiguration(wplConf); socketConf.addService(WhitePages.class.getName(), wplConf.getWhitePages(), 5012); conf.configure(grid1); GridImpl grid2 = new GridImpl(new ConcurrentHashMap<String, Object>()); conf = new GridPeerConfiguration(); // coreServicesMap = Hazelcast.newHazelcastInstance( null ).getMap( // CoreServicesLookup.class.getName() ); coreSeviceConf = new CoreServicesLookupConfiguration(coreServicesMap); conf.addConfiguration(coreSeviceConf); GridPeerServiceConfiguration wprConf = new WhitePagesRemoteConfiguration(); conf.addConfiguration(wprConf); conf.configure(grid2); WhitePages wp = grid2.get(WhitePages.class); wp.create("s1"); wp.create("s2"); wp.create("s3"); GridServiceDescription<String> gs1 = wp.lookup("s1"); gs1.addAddress("p1").setObject("v1"); gs1.addAddress("p2").setObject("v2"); gs1 = wp.lookup("s1"); assertEquals(2, gs1.getAddresses().size()); assertEquals("v1", gs1.getAddresses().get("p1").getObject()); assertEquals("v2", gs1.getAddresses().get("p2").getObject()); gs1.removeAddress("p2"); gs1 = wp.lookup("s1"); assertEquals(1, gs1.getAddresses().size()); assertEquals("v1", gs1.getAddresses().get("p1").getObject()); wp.remove("s1"); assertNull(wp.lookup("s1")); GridServiceDescription gs2 = wp.lookup("s2"); assertNotNull(gs2); grid1.get(SocketService.class).close(); }