public static ReteooStatefulSession readSession(
      MarshallerReaderContext context,
      int id,
      ExecutorService executor,
      Environment environment,
      SessionConfiguration config)
      throws IOException, ClassNotFoundException {

    boolean multithread = context.readBoolean();

    long time = context.readLong();

    FactHandleFactory handleFactory =
        context.ruleBase.newFactHandleFactory(context.readInt(), context.readLong());

    long propagationCounter = context.readLong();

    InternalFactHandle initialFactHandle =
        new DefaultFactHandle(
            context.readInt(), // id
            InitialFactImpl.getInstance(),
            context.readLong(),
            null);

    context.handles.put(initialFactHandle.getId(), initialFactHandle);

    DefaultAgenda agenda =
        context
            .ruleBase
            .getConfiguration()
            .getComponentFactory()
            .getAgendaFactory()
            .createAgenda(context.ruleBase, false);

    readAgenda(context, agenda);
    ReteooStatefulSession session =
        new ReteooStatefulSession(
            id,
            context.ruleBase,
            executor,
            handleFactory,
            initialFactHandle,
            propagationCounter,
            config,
            agenda,
            environment);
    new StatefulKnowledgeSessionImpl(session);

    initialFactHandle.setEntryPoint(
        session.getEntryPoints().get(EntryPoint.DEFAULT.getEntryPointId()));

    return readSession(session, agenda, time, multithread, context);
  }