code: public static ProcessInstanceManager retrieveProcessInstanceManager(Object streamContext) {
          ProcessInstanceManager pim = null;
          if ( streamContext instanceof MarshallerWriteContext ) {
              MarshallerWriteContext context = (MarshallerWriteContext) streamContext;
              pim = ((ProcessRuntimeImpl) ((InternalWorkingMemory) context.wm).getProcessRuntime()).getProcessInstanceManager();
          }
          else if ( streamContext instanceof MarshallerReaderContext ) {
              MarshallerReaderContext context = (MarshallerReaderContext) streamContext;
              pim = ((ProcessRuntimeImpl) ((InternalWorkingMemory) context.wm).getProcessRuntime()).getProcessInstanceManager();
          }
          else {
              throw new UnsupportedOperationException( "Unable to retrieve " + ProcessInstanceManager.class.getSimpleName() + " from "
                                                       + streamContext.getClass().getName() );
          }
          return pim;
      }
docs: Retrieve the {@link ProcessInstanceManager} object from the ObjectOutput- or ObjectInputStream.
  The stream object will secretly also either be a {@link MarshallerReaderContext} or a
  {@link MarshallerWriteContext}.
  @param streamContext The marshaller stream/context.
  @return A {@link ProcessInstanceManager} object.