public RuntimeEngineImpl(KieSession ksession, TaskService taskService) { this.ksession = ksession; this.kieSessionId = ksession.getIdentifier(); this.taskService = taskService; }
public DestroySessionTransactionSynchronization(KieSession ksession) { super(5, "DestroySessionTransactionSynchronization"+ksession.getIdentifier()); this.ksession = ksession; }
public void internalSetKieSession(KieSession ksession) { this.ksession = ksession; this.kieSessionId = ksession.getIdentifier(); }
@Override public void validate(KieSession ksession, Context<?> context) throws IllegalStateException { if (isClosed()) { throw new IllegalStateException("Runtime manager " + identifier + " is already closed"); } RuntimeEngine runtimeInUse = local.get().get(identifier); if (runtimeInUse == null || runtimeInUse.getKieSession().getIdentifier() != ksession.getIdentifier()) { throw new IllegalStateException("Invalid session was used for this context " + context); } }
@Override public void validate(KieSession ksession, Context<?> context) throws IllegalStateException { if (isClosed()) { throw new IllegalStateException("Runtime manager " + identifier + " is already closed"); } if (this.singleton != null && this.singleton.getKieSession().getIdentifier() != ksession.getIdentifier()) { throw new IllegalStateException("Invalid session was used for this context " + context); } }
@Override public KieSession getKieSession() { if (this.disposed) { throw new IllegalStateException("This runtime is already diposed"); } if (ksession == null && initializer != null) { ksession = initializer.initKieSession(context, (InternalRuntimeManager) manager, this); this.kieSessionId = ksession.getIdentifier(); } return this.ksession; }
@Override public void validate(KieSession ksession, Context<?> context) throws IllegalStateException { if (isClosed()) { throw new IllegalStateException("Runtime manager " + identifier + " is already closed"); } if (context == null || context.getContextId() == null) { return; } Long ksessionId = mapper.findMapping(context, this.identifier); if (ksessionId != null && ksession.getIdentifier() != ksessionId) { throw new IllegalStateException("Invalid session was used for this context " + context); } }
@Override public void validate(KieSession ksession, Context<?> context) throws IllegalStateException { if (isClosed()) { throw new IllegalStateException("Runtime manager " + identifier + " is already closed"); } if (context == null || context.getContextId() == null) { return; } Long ksessionId = mapper.findMapping(context, this.identifier); if (ksessionId == null) { // make sure ksession is not use by any other context Object contextId = mapper.findContextId(ksession.getIdentifier(), this.identifier); if (contextId != null && !contextId.equals(context.getContextId().toString())) { throw new IllegalStateException("KieSession with id " + ksession.getIdentifier() + " is already used by another context " + contextId + " expected is "+ context.getContextId()); } return; } if (ksession.getIdentifier() != ksessionId) { throw new IllegalStateException("Invalid session was used for this context " + context); } }
private static long knowledgeSessionDispose(KieSession ksession) { long ksessionId = ksession.getIdentifier(); logger.debug("disposing of ksesssion"); ksession.dispose(); return ksessionId; }
@Override public KieSession newKieSession() { Environment env = environment.getEnvironment(); env.set(EnvironmentName.DEPLOYMENT_ID, owner); KieSession ksession = kbase.newKieSession(environment.getConfiguration(), env); this.sessions.put(ksession.getIdentifier(), ksession); ProcessInstanceManager piManager = ((ProcessRuntimeImpl)((StatefulKnowledgeSessionImpl)ksession).getProcessRuntime()).getProcessInstanceManager(); if (piManager instanceof DefaultProcessInstanceManager) { ((DefaultProcessInstanceManager) piManager).setProcessCounter(processCounter); } return ksession; }
private KieSession reloadSession(KieSession ksession, KieBase kbase, Environment env){ long sessionId = ksession.getIdentifier(); ksession.dispose(); return JPAKnowledgeService.loadStatefulKnowledgeSession( sessionId, kbase, null, env); }
public void destroyCase(CaseContext caseContext) { KieSession kieSession = null; RuntimeEngine localRuntime = findLocalRuntime(caseContext.getContextId()); if (localRuntime != null) { kieSession = localRuntime.getKieSession(); } else { Long ksessionId = mapper.findMapping(caseContext, this.identifier); if (ksessionId != null) { kieSession = factory.findKieSessionById(ksessionId); } } factory.onDispose(kieSession.getIdentifier()); List<ExecutableCommand<?>> cmds = new ArrayList<>(); RemoveMappingCommand removeMapping = new RemoveMappingCommand(mapper, caseContext, getIdentifier()); cmds.add(removeMapping); DestroyKSessionCommand destroy = new DestroyKSessionCommand(kieSession, this); cmds.add(destroy); BatchExecutionCommand batchCmd = new BatchExecutionCommandImpl(cmds); kieSession.execute(batchCmd); }
@Override public AuditEvent buildEvent(ProcessVariableChangedEvent pvce) { long processInstanceId = pvce.getProcessInstance().getId(); String processId = pvce.getProcessInstance().getProcessId(); String variableId = pvce.getVariableId(); String variableInstanceId = pvce.getVariableInstanceId(); String oldValue = (pvce.getOldValue() != null)?pvce.getOldValue().toString():""; String newValue = (pvce.getNewValue() != null)?pvce.getNewValue().toString():""; VariableInstanceLog log = new VariableInstanceLog( processInstanceId, processId, variableInstanceId, variableId, newValue, oldValue); log.setExternalId(""+((KieSession) pvce.getKieRuntime()).getIdentifier()); return log; }
@Override public Void execute(org.kie.api.runtime.Context context) { if (manager.hasEnvironmentEntry("IS_JTA_TRANSACTION", false)) { initialKsession.dispose(); return null; } TransactionManager tm = (TransactionManager) initialKsession.getEnvironment().get(EnvironmentName.TRANSACTION_MANAGER); if (tm != null && tm.getStatus() != TransactionManager.STATUS_NO_TRANSACTION && tm.getStatus() != TransactionManager.STATUS_ROLLEDBACK && tm.getStatus() != TransactionManager.STATUS_COMMITTED) { TransactionManagerHelper.registerTransactionSyncInContainer(tm, new OrderedTransactionSynchronization(5, "PPIRM-" + initialKsession.getIdentifier()) { @Override public void beforeCompletion() { } @Override public void afterCompletion(int arg0) { initialKsession.dispose(); } }); } else { initialKsession.dispose(); } return null; } }
@Override public void afterProcessCompleted(ProcessCompletedEvent event) { mapper.removeMapping(new EnvironmentAwareProcessInstanceContext( event.getKieRuntime().getEnvironment(), event.getProcessInstance().getId()), managerId); factory.onDispose(runtime.getKieSession().getIdentifier()); registerDisposeCallback(runtime, new DestroySessionTransactionSynchronization(runtime.getKieSession()), runtime.getKieSession().getEnvironment()); }
@Override public AuditEvent buildEvent(ProcessStartedEvent pse) { ProcessInstanceImpl pi = (ProcessInstanceImpl) pse.getProcessInstance(); ProcessInstanceLog log = new ProcessInstanceLog(pi.getId(), pi.getProcessId()); log.setExternalId(""+((KieSession) pse.getKieRuntime()).getIdentifier()); log.setProcessName(pi.getProcess().getName()); log.setProcessVersion(pi.getProcess().getVersion()); log.setStatus(ProcessInstance.STATE_ACTIVE); log.setProcessInstanceDescription( pi.getDescription() ); log.setProcessType(((WorkflowProcess)pi.getProcess()).getProcessType()); log.setSlaCompliance(pi.getSlaCompliance()); log.setSlaDueDate(pi.getSlaDueDate()); // store correlation key in its external form CorrelationKey correlationKey = (CorrelationKey) pi.getMetaData().get("CorrelationKey"); if (correlationKey != null) { log.setCorrelationKey(correlationKey.toExternalForm()); } long parentProcessInstanceId = (Long) pi.getMetaData().getOrDefault("ParentProcessInstanceId", -1L); log.setParentProcessInstanceId( parentProcessInstanceId ); return log; }
assertNotNull(ksession); long sessionId = ksession.getIdentifier(); assertTrue(sessionId == 0); assertEquals(sessionId, ksession.getIdentifier()); assertEquals(sessionId, ksession.getIdentifier());
assertNotNull(ksession); long sessionId = ksession.getIdentifier(); assertTrue(sessionId == 0); assertEquals(sessionId, ksession.getIdentifier()); assertEquals(sessionId, ksession.getIdentifier());
assertNotNull(ksession); long sessionId = ksession.getIdentifier(); assertTrue(sessionId == 1); assertEquals(sessionId, ksession.getIdentifier()); assertEquals(sessionId, ksession.getIdentifier());
protected KieSession restoreSession(KieSession ksession, boolean noCache) { if (sessionPersistence) { long id = ksession.getIdentifier(); KieBase kbase = ksession.getKieBase(); Environment env = null; if (noCache) { env = createEnvironment(emf); } else { env = ksession.getEnvironment(); } if( pessimisticLocking ) { env.set(USE_PESSIMISTIC_LOCKING, true); } KieSessionConfiguration config = ksession.getSessionConfiguration(); config.setOption(ForceEagerActivationOption.YES); ksession.dispose(); StatefulKnowledgeSession result = JPAKnowledgeService.loadStatefulKnowledgeSession(id, kbase, config, env); AuditLoggerFactory.newInstance(Type.JPA, result, null); return result; } else { return ksession; } }