public void run() { __log.debug("Starting process definition reaper thread."); long pollingTime = 10000; try { while (true) { Thread.sleep(pollingTime); if (!_mngmtLock.writeLock().tryLock(100L, TimeUnit.MILLISECONDS)) continue; try { __log.debug("Kicking reaper, OProcess instances: " + OProcess.instanceCount); // Copying the runnning process list to avoid synchronization // problems and a potential mess if a policy modifies the list List<BpelProcess> candidates = new ArrayList<BpelProcess>(_registeredProcesses); CollectionsX.remove_if( candidates, new MemberOfFunction<BpelProcess>() { public boolean isMember(BpelProcess o) { return !o.hintIsHydrated(); } }); // And the happy winners are... List<BpelProcess> ripped = _dehydrationPolicy.markForDehydration(candidates); // Bye bye for (BpelProcess process : ripped) { __log.debug("Dehydrating process " + process.getPID()); process.dehydrate(); } } finally { _mngmtLock.writeLock().unlock(); } } } catch (InterruptedException e) { __log.debug(e); } }
public void unregister(QName pid) throws BpelEngineException { if (__log.isTraceEnabled()) __log.trace("unregister: " + pid); try { _mngmtLock.writeLock().lockInterruptibly(); } catch (InterruptedException ie) { __log.debug("unregister() interrupted.", ie); throw new BpelEngineException(__msgs.msgOperationInterrupted()); } try { BpelProcess p; if (_engine != null) { p = _engine.unregisterProcess(pid); if (p != null) { _registeredProcesses.remove(p); XslTransformHandler.getInstance().clearXSLSheets(p.getProcessType()); __log.info(__msgs.msgProcessUnregistered(pid)); } } } catch (Exception ex) { __log.error(__msgs.msgProcessUnregisterFailed(pid), ex); throw new BpelEngineException(ex); } finally { _mngmtLock.writeLock().unlock(); } }
private boolean isLazyHydratable(BpelProcess process) { if (process.isHydrationLazySet()) { return process.isHydrationLazy(); } if (!_hydrationLazy) { return false; } return process.getEstimatedHydratedSize() < _hydrationLazyMinimumSize; }
@SuppressWarnings("unchecked") public Future invoke(Message request, boolean immediate) { if (request == null) { String errmsg = "Must pass non-null message to invoke()!"; __log.fatal(errmsg); throw new NullPointerException(errmsg); } _dao.setRequest(((MessageImpl) request)._dao); _dao.setStatus(MessageExchange.Status.REQUEST.toString()); if (!processInterceptors(this, InterceptorInvoker.__onBpelServerInvoked)) return null; BpelProcess target = _process; if (__log.isDebugEnabled()) __log.debug("invoke() EPR= " + _epr + " ==> " + target); if (target == null) { if (__log.isWarnEnabled()) __log.warn(__msgs.msgUnknownEPR("" + _epr)); setCorrelationStatus(MyRoleMessageExchange.CorrelationStatus.UKNOWN_ENDPOINT); setFailure(MessageExchange.FailureType.UNKNOWN_ENDPOINT, null, null); return null; } else { // Schedule a new job for invocation JobDetails we = new JobDetails(); we.setType(JobType.INVOKE_INTERNAL); we.setInMem(target.isInMemory()); we.setProcessId(target.getPID()); we.setMexId(getDAO().getMessageExchangeId()); if (getOperation().getOutput() != null) { ResponseCallback callback = new ResponseCallback(); _waitingCallbacks.put(getClientId(), callback); } setStatus(Status.ASYNC); Replayer replayer = Replayer.replayer.get(); if (replayer == null) { if (immediate) _engine.onScheduledJob(we); else if (target.isInMemory()) _engine._contexts.scheduler.scheduleVolatileJob(true, we); else _engine._contexts.scheduler.schedulePersistedJob(we, null); } else { replayer.scheduler.schedulePersistedJob(we, null); } return new ResponseFuture(getClientId()); } }
public void release(boolean instanceSucceeded) { if (__log.isDebugEnabled()) __log.debug("Releasing mex " + getMessageExchangeId()); if (_process != null) { _dao.release(_process.isCleanupCategoryEnabled(instanceSucceeded, CLEANUP_CATEGORY.MESSAGES)); } _dao = null; }
public void register(ProcessConf conf) { if (conf == null) throw new NullPointerException("must specify non-null process configuration."); __log.debug("register: " + conf.getProcessId()); // Ok, IO out of the way, we will mod the server state, so need to get a // lock. try { _mngmtLock.writeLock().lockInterruptibly(); } catch (InterruptedException ie) { __log.debug("register(...) interrupted.", ie); throw new BpelEngineException(__msgs.msgOperationInterrupted()); } try { // If the process is already active, do nothing. if (_engine.isProcessRegistered(conf.getProcessId())) { __log.debug( "skipping doRegister" + conf.getProcessId() + ") -- process is already registered"); return; } __log.debug("Registering process " + conf.getProcessId() + " with server."); BpelProcess process = createBpelProcess(conf); process._classLoader = Thread.currentThread().getContextClassLoader(); _engine.registerProcess(process); _registeredProcesses.add(process); if (!isLazyHydratable(process)) { process.hydrate(); } else { _engine.setProcessSize(process.getPID(), false); } __log.info(__msgs.msgProcessRegistered(conf.getProcessId())); } catch (Exception ex) { __log.error(ex); throw new BpelEngineException(ex); } finally { _mngmtLock.writeLock().unlock(); } }
public void invokeInstance(MyRoleMessageExchangeImpl mex, RoutingInfo routing) { Operation operation = getMyRoleOperation(mex.getOperationName()); if (__log.isDebugEnabled()) { __log.debug( "INPUTMSG: " + routing.correlator.getCorrelatorId() + ": ROUTING to existing instance " + routing.messageRoute.getTargetInstance().getInstanceId()); } ProcessInstanceDAO instanceDao = routing.messageRoute.getTargetInstance(); BpelProcess process2 = _process._engine._activeProcesses.get(instanceDao.getProcess().getProcessId()); // Reload process instance for DAO. BpelRuntimeContextImpl instance = process2.createRuntimeContext(instanceDao, null, null); instance.inputMsgMatch(routing.messageRoute.getGroupId(), routing.messageRoute.getIndex(), mex); // Kill the route so some new message does not get routed to // same process instance. routing.correlator.removeRoutes(routing.messageRoute.getGroupId(), instanceDao); // send process instance event CorrelationMatchEvent evt = new CorrelationMatchEvent( new QName(process2.getOProcess().targetNamespace, process2.getOProcess().getName()), process2.getProcessDAO().getProcessId(), instanceDao.getInstanceId(), routing.matchedKeySet); evt.setPortType(mex.getPortType().getQName()); evt.setOperation(operation.getName()); evt.setMexId(mex.getMessageExchangeId()); process2._debugger.onEvent(evt); // store event process2.saveEvent(evt, instanceDao); mex.setCorrelationStatus(MyRoleMessageExchange.CorrelationStatus.MATCHED); mex.getDAO().setInstance(routing.messageRoute.getTargetInstance()); if (mex.getDAO().getCreateTime() == null) mex.getDAO().setCreateTime(instance.getCurrentEventDateTime()); instance.execute(); }
public List<RoutingInfo> findRoute(MyRoleMessageExchangeImpl mex) { List<RoutingInfo> routingInfos = new ArrayList<RoutingInfo>(); if (__log.isTraceEnabled()) { __log.trace( ObjectPrinter.stringifyMethodEnter( this + ":inputMsgRcvd", new Object[] {"messageExchange", mex})); } Operation operation = getMyRoleOperation(mex.getOperationName()); if (operation == null) { __log.error( __msgs.msgUnknownOperation(mex.getOperationName(), _plinkDef.myRolePortType.getQName())); mex.setFailure(MessageExchange.FailureType.UNKNOWN_OPERATION, mex.getOperationName(), null); return null; } setMexRole(mex); // now, the tricks begin: when a message arrives we have to see if there // is anyone waiting for it. Get the correlator, a persisted communication-reduction // data structure supporting correlation correlationKey matching! String correlatorId = BpelProcess.genCorrelatorId(_plinkDef, operation.getName()); CorrelatorDAO correlator = _process.getProcessDAO().getCorrelator(correlatorId); CorrelationKeySet keySet; // We need to compute the correlation keys (based on the operation // we can infer which correlation keys to compute - this is merely a set // consisting of each correlationKey used in each correlation sets // that is ever referenced in an <receive>/<onMessage> on this // partnerlink/operation. try { keySet = computeCorrelationKeys(mex); } catch (InvalidMessageException ime) { // We'd like to do a graceful exit here, no sense in rolling back due to a // a message format problem. __log.debug("Unable to evaluate correlation keys, invalid message format. ", ime); mex.setFailure(MessageExchange.FailureType.FORMAT_ERROR, ime.getMessage(), null); return null; } String mySessionId = mex.getProperty(MessageExchange.PROPERTY_SEP_MYROLE_SESSIONID); String partnerSessionId = mex.getProperty(MessageExchange.PROPERTY_SEP_PARTNERROLE_SESSIONID); if (__log.isDebugEnabled()) { __log.debug( "INPUTMSG: " + correlatorId + ": MSG RCVD keys=" + keySet + " mySessionId=" + mySessionId + " partnerSessionId=" + partnerSessionId); } // Try to find a route for one of our keys. List<MessageRouteDAO> messageRoutes = correlator.findRoute(keySet); if (messageRoutes != null && messageRoutes.size() > 0) { for (MessageRouteDAO messageRoute : messageRoutes) { if (__log.isDebugEnabled()) { __log.debug( "INPUTMSG: " + correlatorId + ": ckeySet " + messageRoute.getCorrelationKeySet() + " route is to " + messageRoute); } routingInfos.add( new RoutingInfo(messageRoute, messageRoute.getCorrelationKeySet(), correlator, keySet)); } } if (routingInfos.size() == 0) { routingInfos.add(new RoutingInfo(null, null, correlator, keySet)); } return routingInfos; }
public ProcessConf getProcessConf() { return (_process.getConf()); }