コード例 #1
0
  public static void readTruthMaintenanceSystem(MarshallerReaderContext context)
      throws IOException {
    ObjectInputStream stream = context.stream;

    TruthMaintenanceSystem tms = context.wm.getTruthMaintenanceSystem();
    while (stream.readShort() == PersisterEnums.EQUALITY_KEY) {
      int status = stream.readInt();
      int factHandleId = stream.readInt();
      InternalFactHandle handle = (InternalFactHandle) context.handles.get(factHandleId);

      // ObjectTypeConf state is not marshalled, so it needs to be re-determined
      ObjectTypeConf typeConf =
          context
              .wm
              .getObjectTypeConfigurationRegistry()
              .getObjectTypeConf(context.wm.getEntryPoint(), handle.getObject());
      if (!typeConf.isTMSEnabled()) {
        typeConf.enableTMS();
      }

      EqualityKey key = new EqualityKey(handle, status);
      handle.setEqualityKey(key);
      while (stream.readShort() == PersisterEnums.FACT_HANDLE) {
        factHandleId = stream.readInt();
        handle = (InternalFactHandle) context.handles.get(factHandleId);
        key.addFactHandle(handle);
        handle.setEqualityKey(key);
      }
      tms.put(key);
    }
  }
コード例 #2
0
  public static void readAgenda(MarshallerReaderContext context, DefaultAgenda agenda)
      throws IOException {
    ObjectInputStream stream = context.stream;

    agenda.setDormantActivations(stream.readInt());
    agenda.setActiveActivations(stream.readInt());

    while (stream.readShort() == PersisterEnums.AGENDA_GROUP) {
      BinaryHeapQueueAgendaGroup group =
          new BinaryHeapQueueAgendaGroup(stream.readUTF(), context.ruleBase);
      group.setActive(stream.readBoolean());
      agenda.getAgendaGroupsMap().put(group.getName(), group);
    }

    while (stream.readShort() == PersisterEnums.AGENDA_GROUP) {
      String agendaGroupName = stream.readUTF();
      agenda.getStackList().add(agenda.getAgendaGroup(agendaGroupName));
    }

    while (stream.readShort() == PersisterEnums.RULE_FLOW_GROUP) {
      String rfgName = stream.readUTF();
      boolean active = stream.readBoolean();
      boolean autoDeactivate = stream.readBoolean();
      RuleFlowGroupImpl rfg = new RuleFlowGroupImpl(rfgName, active, autoDeactivate);
      agenda.getRuleFlowGroupsMap().put(rfgName, rfg);
      int nbNodeInstances = stream.readInt();
      for (int i = 0; i < nbNodeInstances; i++) {
        Long processInstanceId = stream.readLong();
        String nodeInstanceId = stream.readUTF();
        rfg.addNodeInstance(processInstanceId, nodeInstanceId);
      }
    }
  }
コード例 #3
0
  public static void readPropagationContexts(MarshallerReaderContext context) throws IOException {
    ObjectInputStream stream = context.stream;

    while (stream.readShort() == PersisterEnums.PROPAGATION_CONTEXT) {
      readPropagationContext(context);
    }
  }
コード例 #4
0
ファイル: IpcAvl.java プロジェクト: Br3nda/transitime
    /*
     * Custom method of deserializing a SerializationProy object.
     */
    private void readObject(java.io.ObjectInputStream stream)
        throws IOException, ClassNotFoundException {
      short readVersion = stream.readShort();
      if (serializationVersion != readVersion) {
        throw new IOException(
            "Serialization error when reading "
                + getClass().getSimpleName()
                + " object. Read serializationVersion="
                + readVersion);
      }

      // serialization version is OK so read in object
      vehicleId = (String) stream.readObject();
      time = stream.readLong();
      latitude = stream.readFloat();
      longitude = stream.readFloat();
      speed = stream.readFloat();
      heading = stream.readFloat();
      source = (String) stream.readObject();
      assignmentId = (String) stream.readObject();
      assignmentType = (AssignmentType) stream.readObject();
      driverId = (String) stream.readObject();
      licensePlate = (String) stream.readObject();
      passengerCount = stream.readInt();
    }
コード例 #5
0
  /**
   * Reconstitutes this object based on the specified InputStream for JDK Serialization.
   *
   * @param in the input stream to use for reading data to populate this object.
   * @throws IOException if the input stream cannot be used.
   * @throws ClassNotFoundException if a required class needed for instantiation is not available in
   *     the present JVM
   * @since 1.0
   */
  @SuppressWarnings({"unchecked"})
  private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
    in.defaultReadObject();
    short bitMask = in.readShort();

    if (isFieldPresent(bitMask, ID_BIT_MASK)) {
      this.id = (Serializable) in.readObject();
    }
    if (isFieldPresent(bitMask, START_TIMESTAMP_BIT_MASK)) {
      this.startTimestamp = (Date) in.readObject();
    }
    if (isFieldPresent(bitMask, STOP_TIMESTAMP_BIT_MASK)) {
      this.stopTimestamp = (Date) in.readObject();
    }
    if (isFieldPresent(bitMask, LAST_ACCESS_TIME_BIT_MASK)) {
      this.lastAccessTime = (Date) in.readObject();
    }
    if (isFieldPresent(bitMask, TIMEOUT_BIT_MASK)) {
      this.timeout = in.readLong();
    }
    if (isFieldPresent(bitMask, EXPIRED_BIT_MASK)) {
      this.expired = in.readBoolean();
    }
    if (isFieldPresent(bitMask, HOST_BIT_MASK)) {
      this.host = in.readUTF();
    }
    if (isFieldPresent(bitMask, ATTRIBUTES_BIT_MASK)) {
      this.attributes = (Map<Object, Object>) in.readObject();
    }
  }
コード例 #6
0
  public static void readActivations(MarshallerReaderContext context) throws IOException {
    ObjectInputStream stream = context.stream;

    while (stream.readShort() == PersisterEnums.ACTIVATION) {
      readActivation(context);
    }
  }
コード例 #7
0
 public static void readRightTuples(InternalFactHandle factHandle, MarshallerReaderContext context)
     throws IOException {
   ObjectInputStream stream = context.stream;
   while (stream.readShort() == PersisterEnums.RIGHT_TUPLE) {
     readRightTuple(context, factHandle);
   }
 }
コード例 #8
0
 /** java.io.ObjectOutputStream#writeShort(int) */
 public void test_writeShortI() throws Exception {
   // Test for method void java.io.ObjectOutputStream.writeShort(int)
   oos.writeShort(127);
   oos.close();
   ois = new ObjectInputStream(new ByteArrayInputStream(bao.toByteArray()));
   assertEquals("Wrote incorrect short value", 127, ois.readShort());
 }
コード例 #9
0
 private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
   short version = ois.readShort();
   switch (version) {
     case VERSION:
       setUpPropertyEvents();
       break;
     default:
       throw new IOException("Unsupported Serialized Version: " + version);
   }
 }
コード例 #10
0
 private void readObject(ObjectInputStream in) throws IOException {
   short version = in.readShort();
   switch (version) {
     case 0x0001:
       this.value = in.readInt();
       break;
     default:
       throw new UnsupportedVersionException(this, version);
   }
 }
コード例 #11
0
ファイル: TIntShortHashMap.java プロジェクト: allenai/tiburon
  private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
    stream.defaultReadObject();

    int size = stream.readInt();
    setUp(size);
    while (size-- > 0) {
      int key = stream.readInt();
      short val = stream.readShort();
      put(key, val);
    }
  }
コード例 #12
0
  public static void readLeftTuples(MarshallerReaderContext context)
      throws IOException, ClassNotFoundException {
    ObjectInputStream stream = context.stream;

    while (stream.readShort() == PersisterEnums.LEFT_TUPLE) {
      int nodeId = stream.readInt();
      LeftTupleSink sink = (LeftTupleSink) context.sinks.get(nodeId);
      int factHandleId = stream.readInt();
      LeftTuple leftTuple = sink.createLeftTuple(context.handles.get(factHandleId), sink, true);
      readLeftTuple(leftTuple, context);
    }
  }
コード例 #13
0
 /** Run benchmark for given number of batches, with given number of cycles for each batch. */
 void doReps(
     ObjectOutputStream oout, ObjectInputStream oin, StreamBuffer sbuf, int nbatches, int ncycles)
     throws Exception {
   for (int i = 0; i < nbatches; i++) {
     sbuf.reset();
     for (int j = 0; j < ncycles; j++) {
       oout.writeShort(0);
     }
     oout.flush();
     for (int j = 0; j < ncycles; j++) {
       oin.readShort();
     }
   }
 }
コード例 #14
0
/*      */   private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException {
/* 1296 */     s.defaultReadObject();
/* 1297 */     this.n = HashCommon.arraySize(this.size, this.f);
/* 1298 */     this.maxFill = HashCommon.maxFill(this.n, this.f);
/* 1299 */     this.mask = (this.n - 1);
/* 1300 */     long[] key = this.key = new long[this.n];
/* 1301 */     short[] value = this.value = new short[this.n];
/* 1302 */     boolean[] used = this.used = new boolean[this.n];
/* 1303 */     long[] link = this.link = new long[this.n];
/* 1304 */     int prev = -1;
/* 1305 */     this.first = (this.last = -1);
/*      */ 
/* 1308 */     int i = this.size; for (int pos = 0; i-- != 0; ) {
/* 1309 */       long k = s.readLong();
/* 1310 */       short v = s.readShort();
/* 1311 */       pos = (int)HashCommon.murmurHash3(k) & this.mask;
/* 1312 */       while (used[pos] != 0) pos = pos + 1 & this.mask;
/* 1313 */       used[pos] = true;
/* 1314 */       key[pos] = k;
/* 1315 */       value[pos] = v;
/* 1316 */       if (this.first != -1) {
/* 1317 */         link[prev] ^= (link[prev] ^ pos & 0xFFFFFFFF) & 0xFFFFFFFF;
/* 1318 */         link[pos] ^= (link[pos] ^ (prev & 0xFFFFFFFF) << 32) & 0x0;
/* 1319 */         prev = pos;
/*      */       }
/*      */       else {
/* 1322 */         prev = this.first = pos;
/*      */ 
/* 1324 */         link[pos] |= -4294967296L;
/*      */       }
/*      */     }
/* 1327 */     this.last = prev;
/* 1328 */     if (prev != -1)
/*      */     {
/* 1330 */       link[prev] |= 4294967295L;
/*      */     }
/*      */   }
コード例 #15
0
ファイル: IpcVehicle.java プロジェクト: skibu/core
    /*
     * Custom method of deserializing a SerializationProy object.
     */
    protected void readObject(java.io.ObjectInputStream stream)
        throws IOException, ClassNotFoundException {
      // If reading from a newer version of protocol then don't
      // know how to handle it so throw exception
      short readVersion = stream.readShort();
      if (currentSerializationVersion < readVersion) {
        throw new IOException(
            "Serialization error when reading "
                + getClass().getSimpleName()
                + " object. Read version="
                + readVersion
                + " but currently using software version="
                + currentSerializationVersion);
      }

      // serialization version is OK so read in object
      blockId = (String) stream.readObject();
      blockAssignmentMethod = (BlockAssignmentMethod) stream.readObject();
      avl = (IpcAvl) stream.readObject();
      heading = stream.readFloat();
      routeId = (String) stream.readObject();
      routeShortName = (String) stream.readObject();
      tripId = (String) stream.readObject();
      tripPatternId = (String) stream.readObject();
      directionId = (String) stream.readObject();
      headsign = (String) stream.readObject();
      predictable = stream.readBoolean();
      schedBasedPred = stream.readBoolean();
      realTimeSchdAdh = (TemporalDifference) stream.readObject();
      isDelayed = stream.readBoolean();
      isLayover = stream.readBoolean();
      layoverDepartureTime = stream.readLong();
      nextStopId = (String) stream.readObject();
      nextStopName = (String) stream.readObject();
      vehicleType = (String) stream.readObject();
    }
コード例 #16
0
  public static Activation readActivation(MarshallerReaderContext context) throws IOException {
    ObjectInputStream stream = context.stream;
    InternalRuleBase ruleBase = context.ruleBase;
    InternalWorkingMemory wm = context.wm;

    long activationNumber = stream.readLong();

    int pos = stream.readInt();
    LeftTuple leftTuple = context.terminalTupleMap.get(pos);

    int salience = stream.readInt();

    String pkgName = stream.readUTF();
    String ruleName = stream.readUTF();
    Package pkg = ruleBase.getPackage(pkgName);
    Rule rule = pkg.getRule(ruleName);

    RuleTerminalNode ruleTerminalNode = (RuleTerminalNode) leftTuple.getLeftTupleSink();

    PropagationContext pc = context.propagationContexts.get(stream.readLong());

    AgendaItem activation;

    boolean scheduled = false;
    if (rule.getTimer() != null) {
      activation =
          new ScheduledAgendaItem(
              activationNumber, leftTuple, (InternalAgenda) wm.getAgenda(), pc, ruleTerminalNode);
      scheduled = true;
    } else {
      activation = new AgendaItem(activationNumber, leftTuple, salience, pc, ruleTerminalNode);
    }
    leftTuple.setObject(activation);

    if (stream.readBoolean()) {
      String activationGroupName = stream.readUTF();
      ((DefaultAgenda) wm.getAgenda())
          .getActivationGroup(activationGroupName)
          .addActivation(activation);
    }

    boolean activated = stream.readBoolean();
    activation.setActivated(activated);

    if (stream.readBoolean()) {
      InternalFactHandle handle = context.handles.get(stream.readInt());
      activation.setFactHandle(handle);
      handle.setObject(activation);
    }

    InternalAgendaGroup agendaGroup;
    if (rule.getAgendaGroup() == null
        || rule.getAgendaGroup().equals("")
        || rule.getAgendaGroup().equals(AgendaGroup.MAIN)) {
      // Is the Rule AgendaGroup undefined? If it is use MAIN,
      // which is added to the Agenda by default
      agendaGroup =
          (InternalAgendaGroup) ((DefaultAgenda) wm.getAgenda()).getAgendaGroup(AgendaGroup.MAIN);
    } else {
      // AgendaGroup is defined, so try and get the AgendaGroup
      // from the Agenda
      agendaGroup =
          (InternalAgendaGroup)
              ((DefaultAgenda) wm.getAgenda()).getAgendaGroup(rule.getAgendaGroup());
    }

    activation.setAgendaGroup(agendaGroup);

    if (!scheduled && activated) {
      if (rule.getRuleFlowGroup() == null) {
        agendaGroup.add(activation);
      } else {
        InternalRuleFlowGroup rfg =
            (InternalRuleFlowGroup)
                ((DefaultAgenda) wm.getAgenda()).getRuleFlowGroup(rule.getRuleFlowGroup());
        rfg.addActivation(activation);
      }
    }

    TruthMaintenanceSystem tms = context.wm.getTruthMaintenanceSystem();
    while (stream.readShort() == PersisterEnums.LOGICAL_DEPENDENCY) {
      int factHandleId = stream.readInt();
      InternalFactHandle handle = (InternalFactHandle) context.handles.get(factHandleId);
      ObjectTypeConf typeConf =
          context
              .wm
              .getObjectTypeConfigurationRegistry()
              .getObjectTypeConf(
                  ((NamedEntryPoint) handle.getEntryPoint()).getEntryPoint(), handle.getObject());
      tms.addLogicalDependency(handle, activation, pc, rule, typeConf);
    }

    return activation;
  }
コード例 #17
0
  protected void load() throws Exception {
    if (id == null) {
      return;
    }
    File file = getIdAsFile(id, data_suffix);
    if (file == null || !file.exists()) {
      throw new Exception("unexpected condition:not exist:id=" + id);
    }
    if (file.length() == 0) {
      return; // need setRNSDirProps(not null)
    }
    ObjectInputStream ois = null;
    RNSDirectoryProperties newRnsProps = new RNSDirectoryProperties();
    try {
      ois = new ObjectInputStream(new FileInputStream(file));
      /* 1 */
      newRnsProps.setCreateTime((Calendar) ois.readObject());
      /* 2 */
      newRnsProps.setAccessTime((Calendar) ois.readObject());
      /* 3 */
      newRnsProps.setModificationTime((Calendar) ois.readObject());
      /* 4 */
      int size = ois.readInt();
      /* create new list */
      Map<String, RNSEntryData> newlist =
          Collections.synchronizedMap(new HashMap<String, RNSEntryData>());
      for (int i = 0; i < size; i++) {
        /* 5 */
        String keyname = ois.readUTF();
        RNSEntryData ent = new RNSEntryData();
        /* 6 */
        ent.setDirectory(ois.readBoolean());
        /* 7 */
        ent.setLocalID(ois.readUTF());
        if ("".equals(ent.getLocalID())) {
          ent.setLocalID(null);
        }
        /* 8 */
        String eprStr = ois.readUTF();
        if (eprStr != null && eprStr.length() != 0) {
          ent.setEpr(RNSUtil.toEPR(eprStr));
        }
        /* 9 */
        int metalen = ois.readInt();
        if (metalen > 0) {
          MessageElement[] me = new MessageElement[metalen];
          for (int n = 0; n < metalen; n++) {
            /* 10 */
            String xml = ois.readUTF();
            me[n] = RNSUtil.toMessageElement(xml);
          }
          ent.setAny(me);
        }
        newlist.put(keyname, ent);
      }
      ACLEntryType[] newaclents;
      /* ACL */
      int acllen;
      try {
        acllen = ois.readInt(); /* 11 */
      } catch (EOFException eof) {
        acllen = 0;
      }
      if (acllen > 0) {
        newaclents = new ACLEntryType[acllen];
        for (int n = 0; n < acllen; n++) {
          /* 12 */
          newaclents[n] = new ACLEntryType();
          newaclents[n].setType(ois.readShort());
          String aclname = ois.readUTF();
          if (aclname.equals(DUMMY)) {
            aclname = null;
          }
          newaclents[n].setName(aclname);
          newaclents[n].setPerm(ois.readShort());
        }
      } else {
        newaclents = null;
      }

      rnsProps = newRnsProps;
      list = newlist;
      aclents = newaclents;
      logger.debug("load id=" + id);
    } catch (IOException e) {
      throw new Exception("Failed to load resource: id=" + id, e);
    } finally {
      if (ois != null) {
        try {
          ois.close();
        } catch (Exception e2) {
          logger.warn("cannot close: resource id=" + id + ": " + e2.getMessage());
        }
      }
    }
  }
コード例 #18
0
ファイル: Server.java プロジェクト: Aidy121/TeamFortress2RTS
 public void run() {
   Server.preRunOperations(this);
   while (true) {
     try {
       String type = in.readUTF();
       if (type.equals("newObject")) {
         Object object = in.readObject();
         if (object instanceof String) {
           // Adding player..
           this.player = new Player((String) object, Entity.BLUE);
           boolean addPlayer = true;
           for (int i = 0; i < Server.players.size(); i++) {
             if (this.player.name.equals(Server.players.get(i).name)) {
               // Set to online!
               if (Server.players.get(i).online) {
                 System.out.println(
                     "Player " + player.name + " is already connected! " + (userID + 1));
                 this.player = null;
                 addPlayer = false;
               } else {
                 this.player = Server.players.get(i);
                 System.out.println("Returning User: "******", " + (userID + 1));
                 this.player.online = true;
                 addPlayer = false;
               }
               break;
             }
           }
           if (addPlayer) {
             System.out.println("New User: "******", " + (userID + 1));
             Server.players.add(this.player);
           }
         }
       } else if (type.equals(
           "MoveUnit")) { // this needs to require the player to be the owner of the unit
         short unit = in.readShort();
         double cX = in.readDouble();
         double cY = in.readDouble();
         double x = in.readDouble();
         double y = in.readDouble();
         boolean stacked = in.readBoolean();
         // Pretty simple: (If the unit doesn't "exist", game will take care of that.) [Keep in
         // mind, this currently could easily let the player control enemy units]
         new PathFind(
             unit, cX, cY, x, y,
             stacked); // All commands take the liberty of adding themselves to the game stack.
       } else if (type.equals(
           "SetTarget")) { // this needs to require the player to be the owner of the unit
         short unit = in.readShort();
         short enemy = in.readShort();
         boolean stacked = in.readBoolean();
         // Pretty simple:
         new SetTarget(unit, enemy, stacked);
       } else if (type.equals("AddOrder")) {
         short unit = in.readShort();
         byte order = in.readByte();
         double atX = in.readDouble();
         double atY = in.readDouble();
         boolean stacked = in.readBoolean();
         new AddOrder(unit, order, atX, atY, stacked);
       } else if (type.equals("Uber")) {
         short unit = in.readShort();
         boolean stacked = in.readBoolean();
         new Uber(unit, stacked);
       } else if (type.equals("Exiting")) {
         disconnect();
         return;
       }
     } catch (IOException e) {
       disconnect();
       return;
     } catch (Exception e) {
       System.out.println("Alternate error.");
       e.printStackTrace();
     }
   }
 }
コード例 #19
0
  public static void readLeftTuple(LeftTuple parentLeftTuple, MarshallerReaderContext context)
      throws IOException, ClassNotFoundException {
    ObjectInputStream stream = context.stream;
    Map<Integer, BaseNode> sinks = context.sinks;

    LeftTupleSink sink = parentLeftTuple.getLeftTupleSink();

    switch (sink.getType()) {
      case NodeTypeEnums.JoinNode:
        {
          BetaMemory memory = (BetaMemory) context.wm.getNodeMemory((BetaNode) sink);
          addToLeftMemory(parentLeftTuple, memory);

          while (stream.readShort() == PersisterEnums.RIGHT_TUPLE) {
            int childSinkId = stream.readInt();
            LeftTupleSink childSink = (LeftTupleSink) sinks.get(childSinkId);
            int factHandleId = stream.readInt();
            RightTupleKey key = new RightTupleKey(factHandleId, sink);
            RightTuple rightTuple = context.rightTuples.get(key);
            LeftTuple childLeftTuple =
                childSink.createLeftTuple(parentLeftTuple, rightTuple, null, null, childSink, true);
            readLeftTuple(childLeftTuple, context);
          }
          break;
        }
      case NodeTypeEnums.EvalConditionNode:
        {
          while (stream.readShort() == PersisterEnums.LEFT_TUPLE) {
            LeftTupleSink childSink = (LeftTupleSink) sinks.get(stream.readInt());
            LeftTuple childLeftTuple = childSink.createLeftTuple(parentLeftTuple, childSink, true);
            readLeftTuple(childLeftTuple, context);
          }
          break;
        }
      case NodeTypeEnums.NotNode:
      case NodeTypeEnums.ForallNotNode:
        {
          BetaMemory memory = (BetaMemory) context.wm.getNodeMemory((BetaNode) sink);
          int type = stream.readShort();
          if (type == PersisterEnums.LEFT_TUPLE_NOT_BLOCKED) {
            addToLeftMemory(parentLeftTuple, memory);

            while (stream.readShort() == PersisterEnums.LEFT_TUPLE) {
              LeftTupleSink childSink = (LeftTupleSink) sinks.get(stream.readInt());
              LeftTuple childLeftTuple =
                  childSink.createLeftTuple(parentLeftTuple, childSink, true);
              readLeftTuple(childLeftTuple, context);
            }

          } else {
            int factHandleId = stream.readInt();
            RightTupleKey key = new RightTupleKey(factHandleId, sink);
            RightTuple rightTuple = context.rightTuples.get(key);

            parentLeftTuple.setBlocker(rightTuple);
            rightTuple.addBlocked(parentLeftTuple);
          }
          break;
        }
      case NodeTypeEnums.ExistsNode:
        {
          BetaMemory memory = (BetaMemory) context.wm.getNodeMemory((BetaNode) sink);
          int type = stream.readShort();
          if (type == PersisterEnums.LEFT_TUPLE_NOT_BLOCKED) {
            addToLeftMemory(parentLeftTuple, memory);
          } else {
            int factHandleId = stream.readInt();
            RightTupleKey key = new RightTupleKey(factHandleId, sink);
            RightTuple rightTuple = context.rightTuples.get(key);

            parentLeftTuple.setBlocker(rightTuple);
            rightTuple.addBlocked(parentLeftTuple);

            while (stream.readShort() == PersisterEnums.LEFT_TUPLE) {
              LeftTupleSink childSink = (LeftTupleSink) sinks.get(stream.readInt());
              LeftTuple childLeftTuple =
                  childSink.createLeftTuple(parentLeftTuple, childSink, true);
              readLeftTuple(childLeftTuple, context);
            }
          }
          break;
        }
      case NodeTypeEnums.AccumulateNode:
        {
          // accumulate nodes generate new facts on-demand and need special procedures when
          // de-serializing from persistent storage
          AccumulateMemory memory = (AccumulateMemory) context.wm.getNodeMemory((BetaNode) sink);
          memory.betaMemory.getLeftTupleMemory().add(parentLeftTuple);

          AccumulateContext accctx = new AccumulateContext();
          parentLeftTuple.setObject(accctx);

          // first we de-serialize the generated fact handle
          InternalFactHandle handle = readFactHandle(context);
          accctx.result = new RightTuple(handle, (RightTupleSink) sink);

          // then we de-serialize the associated accumulation context
          accctx.context = (Serializable[]) stream.readObject();
          // then we de-serialize the boolean propagated flag
          accctx.propagated = stream.readBoolean();

          // then we de-serialize all the propagated tuples
          short head = -1;
          while ((head = stream.readShort()) != PersisterEnums.END) {
            switch (head) {
              case PersisterEnums.RIGHT_TUPLE:
                {
                  int factHandleId = stream.readInt();
                  RightTupleKey key = new RightTupleKey(factHandleId, sink);
                  RightTuple rightTuple = context.rightTuples.get(key);
                  // just wiring up the match record
                  sink.createLeftTuple(parentLeftTuple, rightTuple, null, null, sink, true);
                  break;
                }
              case PersisterEnums.LEFT_TUPLE:
                {
                  int sinkId = stream.readInt();
                  LeftTupleSink childSink = (LeftTupleSink) sinks.get(sinkId);
                  LeftTuple childLeftTuple =
                      new LeftTupleImpl(parentLeftTuple, accctx.result, childSink, true);
                  readLeftTuple(childLeftTuple, context);
                  break;
                }
              default:
                {
                  throw new RuntimeDroolsException(
                      "Marshalling error. This is a bug. Please contact the development team.");
                }
            }
          }
          break;
        }
      case NodeTypeEnums.RightInputAdaterNode:
        {
          // RIANs generate new fact handles on-demand to wrap tuples and need special procedures
          // when de-serializing from persistent storage
          ObjectHashMap memory = (ObjectHashMap) context.wm.getNodeMemory((NodeMemory) sink);
          // create fact handle
          int id = stream.readInt();
          long recency = stream.readLong();
          InternalFactHandle handle =
              new DefaultFactHandle(
                  id,
                  parentLeftTuple,
                  recency,
                  context.wm.getEntryPoints().get(EntryPoint.DEFAULT.getEntryPointId()));
          memory.put(parentLeftTuple, handle);

          readRightTuples(handle, context);

          stream.readShort(); // Persistence.END
          break;
        }
      case NodeTypeEnums.FromNode:
        {
          //              context.out.println( "FromNode" );
          // FNs generate new fact handles on-demand to wrap objects and need special procedures
          // when serializing to persistent storage
          FromMemory memory = (FromMemory) context.wm.getNodeMemory((NodeMemory) sink);

          memory.betaMemory.getLeftTupleMemory().add(parentLeftTuple);
          Map<Object, RightTuple> matches = new LinkedHashMap<Object, RightTuple>();
          parentLeftTuple.setObject(matches);

          while (stream.readShort() == PersisterEnums.FACT_HANDLE) {
            // we de-serialize the generated fact handle ID
            InternalFactHandle handle = readFactHandle(context);
            context.handles.put(handle.getId(), handle);
            readRightTuples(handle, context);
            matches.put(handle.getObject(), handle.getFirstRightTuple());
          }
          while (stream.readShort() == PersisterEnums.RIGHT_TUPLE) {
            LeftTupleSink childSink = (LeftTupleSink) sinks.get(stream.readInt());
            int factHandleId = stream.readInt();
            RightTupleKey key =
                new RightTupleKey(
                    factHandleId, null); // created tuples in from node always use null sink
            RightTuple rightTuple = context.rightTuples.get(key);
            LeftTuple childLeftTuple =
                new LeftTupleImpl(parentLeftTuple, rightTuple, childSink, true);
            readLeftTuple(childLeftTuple, context);
          }
          //                context.out.println( "FromNode   ---   END" );
          break;
        }
      case NodeTypeEnums.UnificationNode:
        {
          boolean isOpen = context.readBoolean();

          if (isOpen) {
            QueryElementNode node = (QueryElementNode) sink;
            InternalFactHandle handle = readFactHandle(context);
            context.handles.put(handle.getId(), handle);
            node.createDroolsQuery(parentLeftTuple, handle, context.wm);
            readLeftTuples(context);
          } else {
            while (stream.readShort() == PersisterEnums.LEFT_TUPLE) {
              LeftTupleSink childSink = (LeftTupleSink) sinks.get(stream.readInt());
              // we de-serialize the generated fact handle ID
              InternalFactHandle handle = readFactHandle(context);
              context.handles.put(handle.getId(), handle);
              RightTuple rightTuple = new RightTuple(handle);
              // @TODO check if open query
              LeftTuple childLeftTuple =
                  new LeftTupleImpl(parentLeftTuple, rightTuple, childSink, true);
              readLeftTuple(childLeftTuple, context);
            }
          }
          break;
        }
      case NodeTypeEnums.RuleTerminalNode:
        {
          int pos = context.terminalTupleMap.size();
          context.terminalTupleMap.put(pos, parentLeftTuple);
          break;
        }
      case NodeTypeEnums.QueryTerminalNode:
        {
          boolean unificationNode = context.readBoolean();
          if (unificationNode) {
            // we de-serialize the generated fact handle ID
            InternalFactHandle handle = readFactHandle(context);
            context.handles.put(handle.getId(), handle);
            RightTuple rightTuple = new RightTuple(handle);
            parentLeftTuple.setObject(rightTuple);

            LeftTuple entry = parentLeftTuple;

            // find the DroolsQuery object
            while (entry.getParent() != null) {
              entry = entry.getParent();
            }
            DroolsQuery query = (DroolsQuery) entry.getLastHandle().getObject();
            LeftTuple leftTuple =
                ((UnificationNodeViewChangedEventListener) query.getQueryResultCollector())
                    .getLeftTuple();

            while (stream.readShort() == PersisterEnums.LEFT_TUPLE) {
              LeftTupleSink childSink = (LeftTupleSink) sinks.get(stream.readInt());
              // @TODO check if open query!!!
              LeftTuple childLeftTuple =
                  childSink.createLeftTuple(leftTuple, rightTuple, childSink);
              readLeftTuple(childLeftTuple, context);
            }
          }
          break;
        }
    }
  }
コード例 #20
0
 @Override
 protected void readEvent(ObjectInputStream in) throws IOException, ClassNotFoundException {
   ini(MainType.TYPE_ENTITY, (SubType) in.readObject(), (Serializable) in.readObject());
   id = in.readShort();
 }