congrats Icon
New! Announcing Tabnine Chat Beta
Learn More
Tabnine Logo
Marshaller
Code IndexAdd Tabnine to your IDE (free)

How to use
Marshaller
in
org.kie.api.marshalling

Best Java code snippets using org.kie.api.marshalling.Marshaller (Showing top 20 results out of 315)

origin: kiegroup/jbpm

marshaller.marshall( baos, session );
byte[] b1 = baos.toByteArray();
baos.close();
StatefulKnowledgeSession session2 = (StatefulKnowledgeSession) marshaller.unmarshall( bais );
origin: kiegroup/jbpm

public static byte [] serializeKnowledgeSession(Marshaller marshaller, 
                        StatefulKnowledgeSession ksession) 
                        throws Exception { 
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
  marshaller.marshall( bos, ksession );
  byte[] ksessionBytes = bos.toByteArray();
  bos.close();
  
  return ksessionBytes;
}

origin: kiegroup/jbpm

public static StatefulKnowledgeSession deserializeKnowledgeSession(Marshaller marshaller, 
                                  byte [] serializedKsession) 
                                  throws Exception {
  
  ByteArrayInputStream bais = new ByteArrayInputStream( serializedKsession );
  StatefulKnowledgeSession deserializedKsession = (StatefulKnowledgeSession)
    marshaller.unmarshall( bais,
                SessionConfiguration.newInstance(),
                EnvironmentFactory.newEnvironment() );
  bais.close();
  
  return deserializedKsession;
} 

origin: org.drools/drools-persistence-jpa

                            env );
MarshallingConfigurationImpl config = (MarshallingConfigurationImpl)
    this.marshallingHelper.getMarshaller().getMarshallingConfiguration();
config.setMarshallProcessInstances( false );
config.setMarshallWorkItems( false );
origin: org.drools/drools-compiler

@Test
public void testMarshallWithNot() throws Exception {
  String str =
      "import " + getClass().getCanonicalName() + ".*\n" +
          "rule one\n" +
          "when\n" +
          "   A()\n" +
          "   not(B())\n" +
          "then\n" +
          "System.out.println(\"a\");\n" +
          "end\n" +
          "\n" +
          "rule two\n" +
          "when\n" +
          "   A()\n" +
          "then\n" +
          "System.out.println(\"b\");\n" +
          "end\n";
  KieBaseConfiguration config = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
  config.setOption( EventProcessingOption.STREAM );
  KieBase kBase = loadKnowledgeBaseFromString(config, str);
  KieSession ksession = kBase.newKieSession();
  ksession.insert( new A() );
  MarshallerFactory.newMarshaller( kBase ).marshall( new ByteArrayOutputStream(), ksession );
}
origin: org.drools/drools-compiler

public KieSession loadSession( FileInputStream input ) throws IOException, ClassNotFoundException {
  KieSession ksession = null;
  DroolsObjectInputStream droolsIn = new DroolsObjectInputStream( input, this.getClass().getClassLoader() );
  try {
    KieBase kbase = (KieBase) droolsIn.readObject();
    Marshaller mas = createMarshaller( kbase );
    ksession = mas.unmarshall(droolsIn);
  } catch ( EOFException e ) {
    e.printStackTrace();
    fail( e.getMessage() );
  } finally {
    droolsIn.close();
  }
  return ksession;
}
origin: org.drools/drools-persistence-jpa

protected void initNewKnowledgeSession(KieBase kbase, KieSessionConfiguration conf) {
  this.sessionInfo = new SessionInfo();
  // create session but bypass command service
  this.ksession = kbase.newKieSession( conf,
                     this.env );
  initKieSessionMBeans(this.ksession);
  this.marshallingHelper = new SessionMarshallingHelper( this.ksession, conf );
  MarshallingConfigurationImpl config = (MarshallingConfigurationImpl) this.marshallingHelper.getMarshaller().getMarshallingConfiguration();
  config.setMarshallProcessInstances( false );
  config.setMarshallWorkItems( false );
  this.sessionInfo.setJPASessionMashallingHelper( this.marshallingHelper );
  ((InternalKnowledgeRuntime) this.ksession).setEndOperationListener( new EndOperationListenerImpl(this.txm, this.sessionInfo ) );
  this.runner = new TransactionInterceptor();
  TimerJobFactoryManager timerJobFactoryManager = ((InternalKnowledgeRuntime) ksession ).getTimerService().getTimerJobFactoryManager();
  if (timerJobFactoryManager instanceof CommandServiceTimerJobFactoryManager) {
    ( (CommandServiceTimerJobFactoryManager) timerJobFactoryManager ).setRunner( this );
  }
}
origin: org.drools/drools-compiler

private void readWrite(KieBase knowledgeBase,
            KieSession ksession,
            KieSessionConfiguration config) {
  try {
    Marshaller marshaller = MarshallerFactory.newMarshaller( knowledgeBase );
    ByteArrayOutputStream o = new ByteArrayOutputStream();
    marshaller.marshall( o, ksession );
    ksession = marshaller.unmarshall( new ByteArrayInputStream( o.toByteArray() ), config, KieServices.get().newEnvironment() );
    ksession.fireAllRules();
    //scheduler = ksession.<SessionClock>getSessionClock();
  } catch ( Exception e ) {
    throw new RuntimeException( e );
  }
}
origin: org.drools/drools-compiler

public void saveSession( FileOutputStream output, KieSession ksession ) throws IOException {
  DroolsObjectOutputStream droolsOut = new DroolsObjectOutputStream( output );
  droolsOut.writeObject( ksession.getKieBase() );
  Marshaller mas = createMarshaller( ksession.getKieBase() );
  mas.marshall( droolsOut, ksession );
  droolsOut.flush();
  droolsOut.close();
}
origin: OpenNMS/opennms

private void unmarshallStateFromDisk(boolean serialize) {
  final File stateFile = getPathToState().toFile();
  if (!stateFile.exists()) {
    LOG.error("Can't restore state from {} because the file doesn't exist", stateFile);
    return;
  }
  LOG.debug("Restoring state for engine {} from {} ...", m_name, stateFile);
  final KieMarshallers kMarshallers = KieServices.Factory.get().getMarshallers();
  final ObjectMarshallingStrategy oms = serialize ?
      kMarshallers.newSerializeMarshallingStrategy() : kMarshallers.newIdentityMarshallingStrategy();
  final Marshaller marshaller = kMarshallers.newMarshaller( m_kieBase, new ObjectMarshallingStrategy[]{ oms } );
  try (FileInputStream fin = new FileInputStream(stateFile)) {
    marshaller.unmarshall( fin, m_kieSession );
    stateFile.delete();
    LOG.info("Sucessfully restored state for engine {} from {}.", m_name, stateFile);
  } catch (IOException | ClassNotFoundException e) {
    LOG.error("Failed to restore state for engine {} from {}.", m_name, stateFile, e);
  }
}
origin: org.drools/drools-compiler

public static KieSession marshallAndUnmarshall(KieServices ks, KieBase kbase, KieSession ksession, KieSessionConfiguration sessionConfig) {
  // Serialize and Deserialize
  try {
    Marshaller marshaller = ks.getMarshallers().newMarshaller(kbase);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    marshaller.marshall(baos, ksession);
    marshaller = MarshallerFactory.newMarshaller(kbase);
    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    baos.close();
    ksession = marshaller.unmarshall(bais, sessionConfig, null);
    bais.close();
  } catch (Exception e) {
    e.printStackTrace();
    fail("unexpected exception :" + e.getMessage());
  }
  return ksession;
}

origin: org.opennms/drools-correlation-engine

private void marshallStateToDisk(boolean serialize) {
  final File stateFile = getPathToState().toFile();
  LOG.debug("Saving state for engine {} in {} ...", m_name, stateFile);
  final KieMarshallers kMarshallers = KieServices.Factory.get().getMarshallers();
  final ObjectMarshallingStrategy oms = serialize ?
      kMarshallers.newSerializeMarshallingStrategy() : kMarshallers.newIdentityMarshallingStrategy();
  final Marshaller marshaller = kMarshallers.newMarshaller( m_kieBase, new ObjectMarshallingStrategy[]{ oms } );
  try (FileOutputStream fos = new FileOutputStream(stateFile)) {
    m_kieSession.halt();
    marshaller.marshall( fos, m_kieSession );
    m_kieSession.dispose();
    m_kieSession.destroy();
    LOG.info("Sucessfully save state for engine {} in {}.", m_name, stateFile);
  } catch (IOException e) {
    LOG.error("Failed to save state for engine {} in {}.", m_name, stateFile, e);
  }
}
origin: org.opennms/drools-correlation-engine

private void unmarshallStateFromDisk(boolean serialize) {
  final File stateFile = getPathToState().toFile();
  if (!stateFile.exists()) {
    LOG.error("Can't restore state from {} because the file doesn't exist", stateFile);
    return;
  }
  LOG.debug("Restoring state for engine {} from {} ...", m_name, stateFile);
  final KieMarshallers kMarshallers = KieServices.Factory.get().getMarshallers();
  final ObjectMarshallingStrategy oms = serialize ?
      kMarshallers.newSerializeMarshallingStrategy() : kMarshallers.newIdentityMarshallingStrategy();
  final Marshaller marshaller = kMarshallers.newMarshaller( m_kieBase, new ObjectMarshallingStrategy[]{ oms } );
  try (FileInputStream fin = new FileInputStream(stateFile)) {
    marshaller.unmarshall( fin, m_kieSession );
    stateFile.delete();
    LOG.info("Sucessfully restored state for engine {} from {}.", m_name, stateFile);
  } catch (IOException | ClassNotFoundException e) {
    LOG.error("Failed to restore state for engine {} from {}.", m_name, stateFile, e);
  }
}
origin: org.drools/drools-compiler

public static KieSession marshallAndUnmarshall(KieBase kbase1, KieBase kbase2, KieSession ksession, KieSessionConfiguration sessionConfig) {
  // Serialize and Deserialize
  try {
    KieMarshallers kieMarshallers = KieServices.Factory.get().getMarshallers();
    Marshaller marshaller = kieMarshallers.newMarshaller( kbase1 );
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    marshaller.marshall(baos, ksession);
    marshaller = kieMarshallers.newMarshaller( kbase2 );
    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    baos.close();
    ksession = marshaller.unmarshall(bais, sessionConfig, null);
    bais.close();
  } catch (Exception e) {
    e.printStackTrace();
    fail("unexpected exception :" + e.getMessage());
  }
  return ksession;
}
origin: OpenNMS/opennms

private void marshallStateToDisk(boolean serialize) {
  final File stateFile = getPathToState().toFile();
  LOG.debug("Saving state for engine {} in {} ...", m_name, stateFile);
  final KieMarshallers kMarshallers = KieServices.Factory.get().getMarshallers();
  final ObjectMarshallingStrategy oms = serialize ?
      kMarshallers.newSerializeMarshallingStrategy() : kMarshallers.newIdentityMarshallingStrategy();
  final Marshaller marshaller = kMarshallers.newMarshaller( m_kieBase, new ObjectMarshallingStrategy[]{ oms } );
  try (FileOutputStream fos = new FileOutputStream(stateFile)) {
    m_kieSession.halt();
    marshaller.marshall( fos, m_kieSession );
    m_kieSession.dispose();
    m_kieSession.destroy();
    LOG.info("Sucessfully save state for engine {} in {}.", m_name, stateFile);
  } catch (IOException e) {
    LOG.error("Failed to save state for engine {} in {}.", m_name, stateFile, e);
  }
}
origin: OpenNMS/opennms

/**
 * Unmarshall state from disk.
 *
 * @param serialize the serialize
 */
private void unmarshallStateFromDisk(boolean serialize) {
  final File stateFile = getPathToState().toFile();
  LOG.debug("Restoring state for engine {} from {} ...", getName(), stateFile);
  if (!stateFile.exists()) return;
  final KieMarshallers kMarshallers = KieServices.Factory.get().getMarshallers();
  final ObjectMarshallingStrategy oms = serialize ? kMarshallers.newSerializeMarshallingStrategy() : kMarshallers.newIdentityMarshallingStrategy();
  final Marshaller marshaller = kMarshallers.newMarshaller( m_kieBase, new ObjectMarshallingStrategy[]{ oms } );
  try (FileInputStream fin = new FileInputStream(stateFile)) {
    marshaller.unmarshall( fin, m_kieSession );
    stateFile.delete();
    LOG.info("Sucessfully restored state for engine {} from {}. There are {} elements on the working memory.", getName(), stateFile, m_kieSession.getObjects().size());
  } catch (IOException | ClassNotFoundException e) {
    LOG.error("Failed to restore state for engine {} from {}.", getName(), stateFile, e);
  }
}
origin: org.drools/drools-compiler

@Test
public void testMarshallWithCollects() throws Exception {
  // BZ-1193600
  String str =
      "import java.util.Collection\n" +
      "rule R1 when\n" +
      "    Collection(empty==false) from collect( Integer() )\n" +
      "    Collection() from collect( String() )\n" +
      "then\n" +
      "end\n" +
      "rule R2 when then end\n";
  KieBase kbase = new KieHelper().addContent(str, ResourceType.DRL).build();
  KieSession ksession = kbase.newKieSession();
  try {
    Marshaller marshaller = MarshallerFactory.newMarshaller(kbase);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    marshaller.marshall(baos, ksession);
    marshaller = MarshallerFactory.newMarshaller(kbase);
    ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
    baos.close();
    ksession = marshaller.unmarshall(bais);
    bais.close();
  } catch (Exception e) {
    e.printStackTrace();
    fail("unexpected exception :" + e.getMessage());
  }
}
origin: OpenNMS/opennms

/**
 * Marshall state to disk.
 *
 * @param serialize the serialize
 */
private void marshallStateToDisk(boolean serialize) {
  final File stateFile = getPathToState().toFile();
  LOG.debug("Saving state for engine {} in {} ...", getName(), stateFile);
  final KieMarshallers kMarshallers = KieServices.Factory.get().getMarshallers();
  final ObjectMarshallingStrategy oms = serialize ? kMarshallers.newSerializeMarshallingStrategy() : kMarshallers.newIdentityMarshallingStrategy();
  final Marshaller marshaller = kMarshallers.newMarshaller( m_kieBase, new ObjectMarshallingStrategy[]{ oms } );
  try (FileOutputStream fos = new FileOutputStream(stateFile)) {
    m_kieSession.halt();
    marshaller.marshall( fos, m_kieSession );
    m_kieSession.dispose();
    m_kieSession.destroy();
    LOG.info("Sucessfully save state for engine {} in {}. There are {} elements on the working memory.", getName(), stateFile, m_kieSession.getObjects().size());
  } catch (IOException e) {
    LOG.error("Failed to save state for engine {} in {}.", getName(), stateFile, e);
  }
}
origin: org.drools/drools-compiler

private KieSession marsallStatefulKnowledgeSession(KieSession ksession) throws IOException,
                                                  ClassNotFoundException {
  Globals globals = ksession.getGlobals();
  KieBase kbase = ksession.getKieBase();
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  MarshallerFactory.newMarshaller( kbase ).marshall( out,
                            ksession );
  KieSessionConfiguration ksconf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
  ksconf.setOption( TimerJobFactoryOption.get("trackable") );
  ksconf.setOption( ClockTypeOption.get( "pseudo" ) );
  Environment env = EnvironmentFactory.newEnvironment();
  env.set( EnvironmentName.GLOBALS, globals );
  ksession = MarshallerFactory.newMarshaller( kbase ).unmarshall( new ByteArrayInputStream( out.toByteArray() ), ksconf, env );
  return ksession;
}
origin: org.drools/drools-reteoo

@Test
public void testMarshallWithNot() throws Exception {
  String str =
      "import " + getClass().getCanonicalName() + ".*\n" +
      "rule one\n" +
      "when\n" +
      "   A()\n" +
      "   not(B())\n" +
      "then\n" +
      "System.out.println(\"a\");\n" +
      "end\n" +
      "\n" +
      "rule two\n" +
      "when\n" +
      "   A()\n" +
      "then\n" +
      "System.out.println(\"b\");\n" +
      "end\n";
  KieBaseConfiguration config = KnowledgeBaseFactory .newKnowledgeBaseConfiguration();
  config.setOption( EventProcessingOption.STREAM );
  KnowledgeBase kBase = loadKnowledgeBaseFromString(config, str);
  StatefulKnowledgeSession ksession = kBase.newStatefulKnowledgeSession();
  ksession.insert( new A() );
  MarshallerFactory.newMarshaller( kBase ).marshall( new ByteArrayOutputStream(), ksession );
}
org.kie.api.marshallingMarshaller

Most used methods

  • marshall
    Marshalls the given KieSession into the provided OutputStream
  • unmarshall
    Creates KieSession using the given KieSessionConfiguration and Environment. It will then unmarshall
  • getMarshallingConfiguration

Popular in Java

  • Running tasks concurrently on multiple threads
  • getApplicationContext (Context)
  • scheduleAtFixedRate (Timer)
  • setContentView (Activity)
  • ObjectMapper (com.fasterxml.jackson.databind)
    ObjectMapper provides functionality for reading and writing JSON, either to and from basic POJOs (Pl
  • URL (java.net)
    A Uniform Resource Locator that identifies the location of an Internet resource as specified by RFC
  • UnknownHostException (java.net)
    Thrown when a hostname can not be resolved.
  • JTextField (javax.swing)
  • FileUtils (org.apache.commons.io)
    General file manipulation utilities. Facilities are provided in the following areas: * writing to a
  • Table (org.hibernate.mapping)
    A relational table
  • From CI to AI: The AI layer in your organization
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now