public static void writeWorkItem(MarshallerWriteContext context, WorkItem workItem) throws IOException { ObjectOutputStream stream = context.stream; stream.writeLong(workItem.getId()); stream.writeLong(workItem.getProcessInstanceId()); stream.writeUTF(workItem.getName()); stream.writeInt(workItem.getState()); // Work Item Parameters Map<String, Object> parameters = workItem.getParameters(); Collection<Object> notNullValues = new ArrayList<Object>(); for (Object value : parameters.values()) { if (value != null) { notNullValues.add(value); } } stream.writeInt(notNullValues.size()); for (String key : parameters.keySet()) { Object object = parameters.get(key); if (object != null) { stream.writeUTF(key); ObjectMarshallingStrategy strategy = context.objectMarshallingStrategyStore.getStrategyObject(object); String strategyClassName = strategy.getClass().getName(); stream.writeInt(-2); // backwards compatibility stream.writeUTF(strategyClassName); if (strategy.accept(object)) { strategy.write(stream, object); } } } }
public static void writeActivation( MarshallerWriteContext context, LeftTuple leftTuple, AgendaItem agendaItem, RuleTerminalNode ruleTerminalNode) throws IOException { ObjectOutputStream stream = context.stream; stream.writeLong(agendaItem.getActivationNumber()); stream.writeInt(context.terminalTupleMap.get(leftTuple)); stream.writeInt(agendaItem.getSalience()); Rule rule = agendaItem.getRule(); stream.writeUTF(rule.getPackage()); stream.writeUTF(rule.getName()); // context.out.println( "Rule " + rule.getPackage() + "." + rule.getName() ); // context.out.println( "AgendaItem long:" + // agendaItem.getPropagationContext().getPropagationNumber() ); stream.writeLong(agendaItem.getPropagationContext().getPropagationNumber()); if (agendaItem.getActivationGroupNode() != null) { stream.writeBoolean(true); // context.out.println( "ActivationGroup bool:" + true ); stream.writeUTF(agendaItem.getActivationGroupNode().getActivationGroup().getName()); // context.out.println( "ActivationGroup string:" + // agendaItem.getActivationGroupNode().getActivationGroup().getName() ); } else { stream.writeBoolean(false); // context.out.println( "ActivationGroup bool:" + false ); } stream.writeBoolean(agendaItem.isActivated()); // context.out.println( "AgendaItem bool:" + agendaItem.isActivated() ); if (agendaItem.getFactHandle() != null) { stream.writeBoolean(true); stream.writeInt(agendaItem.getFactHandle().getId()); } else { stream.writeBoolean(false); } org.drools.core.util.LinkedList list = agendaItem.getLogicalDependencies(); if (list != null && !list.isEmpty()) { for (LogicalDependency node = (LogicalDependency) list.getFirst(); node != null; node = (LogicalDependency) node.getNext()) { stream.writeShort(PersisterEnums.LOGICAL_DEPENDENCY); stream.writeInt(((InternalFactHandle) node.getJustified()).getId()); // context.out.println( "Logical Depenency : int " + ((InternalFactHandle) // node.getFactHandle()).getId() ); } } stream.writeShort(PersisterEnums.END); }
private static void writeFactHandle( MarshallerWriteContext context, ObjectOutputStream stream, ObjectMarshallingStrategyStore objectMarshallingStrategyStore, int type, InternalFactHandle handle) throws IOException { stream.writeInt(type); stream.writeInt(handle.getId()); stream.writeLong(handle.getRecency()); if (type == 2) { // is event EventFactHandle efh = (EventFactHandle) handle; stream.writeLong(efh.getStartTimestamp()); stream.writeLong(efh.getDuration()); stream.writeBoolean(efh.isExpired()); stream.writeLong(efh.getActivationsCount()); } // context.out.println( "Object : int:" + handle.getId() + " long:" + handle.getRecency() ); // context.out.println( handle.getObject() ); Object object = handle.getObject(); // Old versions wrote -1 and tested >= 0 to see if there was a strategy available // Now, we write -2 to indicate that we write the strategy class name to the stream stream.writeInt(-2); if (object != null) { ObjectMarshallingStrategy strategy = objectMarshallingStrategyStore.getStrategyObject(object); String strategyClassName = strategy.getClass().getName(); stream.writeUTF(strategyClassName); strategy.write(stream, object); } else { stream.writeUTF(""); } if (handle.getEntryPoint() instanceof InternalWorkingMemoryEntryPoint) { String entryPoint = ((InternalWorkingMemoryEntryPoint) handle.getEntryPoint()) .getEntryPoint() .getEntryPointId(); if (entryPoint != null && !entryPoint.equals("")) { stream.writeBoolean(true); stream.writeUTF(entryPoint); } else { stream.writeBoolean(false); } } else { stream.writeBoolean(false); } }
/** * Saves the object to an object output stream * * @param ostream the object stream to be writing to * @throws IOException an I/O exception of some sort has occurred */ private void writeObject(ObjectOutputStream ostream) throws IOException { ostream.writeObject(getTitle()); ostream.writeObject(getDescription()); ostream.writeObject(getLocation()); ostream.writeLong(getDuration()); ostream.writeObject(getPattern()); }
/** * Serializes this object to the specified output stream for JDK Serialization. * * @param out output stream used for Object serialization. * @throws IOException if any of this object's fields cannot be written to the stream. * @since 1.0 */ private void writeObject(ObjectOutputStream out) throws IOException { out.defaultWriteObject(); short alteredFieldsBitMask = getAlteredFieldsBitMask(); out.writeShort(alteredFieldsBitMask); if (id != null) { out.writeObject(id); } if (startTimestamp != null) { out.writeObject(startTimestamp); } if (stopTimestamp != null) { out.writeObject(stopTimestamp); } if (lastAccessTime != null) { out.writeObject(lastAccessTime); } if (timeout != 0l) { out.writeLong(timeout); } if (expired) { out.writeBoolean(expired); } if (host != null) { out.writeUTF(host); } if (!CollectionUtils.isEmpty(attributes)) { out.writeObject(attributes); } }
private void writeObject(java.io.ObjectOutputStream out) throws IOException { out.writeObject(name); out.writeInt(resourceId); out.writeInt(value); if (iptv == null) { // No POI vector out.writeInt(0); return; } long vectorSize = iptv.size(); out.writeLong(vectorSize); Log.d(TAG, "Written vector size: " + vectorSize); for (int j = 0; j < vectorSize; j++) { Ipoint p = iptv.get(j); out.writeFloat(p.getX()); out.writeFloat(p.getY()); out.writeFloat(p.getScale()); out.writeFloat(p.getOrientation()); out.writeInt(p.getLaplacian()); out.writeFloat(p.getDx()); out.writeFloat(p.getDy()); out.writeInt(p.getClusterIndex()); out.writeObject(p.getDescriptor()); } }
/** java.io.ObjectOutputStream#writeLong(long) */ public void test_writeLongJ() throws Exception { // Test for method void java.io.ObjectOutputStream.writeLong(long) oos.writeLong(Long.MAX_VALUE); oos.close(); ois = new ObjectInputStream(new ByteArrayInputStream(bao.toByteArray())); assertTrue("Wrote incorrect double value", ois.readLong() == Long.MAX_VALUE); }
// --------------------------------------------------------------------------- private void writeCache() { try { Debug.print("Writing cache"); FileOutputStream fos = new FileOutputStream(m_cacheFile); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject(m_depCache); oos.writeInt(m_newModificationCache.size()); Iterator<String> it = m_newModificationCache.keySet().iterator(); while (it.hasNext()) { String key = it.next(); oos.writeUTF(key); oos.writeLong(m_newModificationCache.get(key)); } oos.close(); } catch (Exception e) { Debug.print(e.getMessage()); StringWriter sw = new StringWriter(); e.printStackTrace(new PrintWriter(sw)); Debug.print(sw.toString()); } }
/** * Serializes and Base64 encodes the provided <code>state</code> to the provided <code>writer * </code>/ * * @param state view state * @param writer the <code>Writer</code> to write the content to * @throws IOException if an error occurs writing the state to the client */ protected void doWriteState(Object state, Writer writer) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); OutputStream base = null; if (compressViewState) { base = new GZIPOutputStream(baos, csBuffSize); } else { base = baos; } ObjectOutputStream oos = null; try { oos = serialProvider.createObjectOutputStream(new BufferedOutputStream(base)); if (stateTimeoutEnabled) { oos.writeLong(System.currentTimeMillis()); } Object[] stateToWrite = (Object[]) state; //noinspection NonSerializableObjectPassedToObjectStream oos.writeObject(stateToWrite[0]); //noinspection NonSerializableObjectPassedToObjectStream oos.writeObject(stateToWrite[1]); oos.flush(); oos.close(); oos = null; // get bytes for encrypting byte[] bytes = baos.toByteArray(); if (guard != null) { // this will MAC bytes = guard.encrypt(bytes); } // Base 64 encode Base64OutputStreamWriter bos = new Base64OutputStreamWriter(bytes.length, writer); bos.write(bytes, 0, bytes.length); bos.finish(); if (LOGGER.isLoggable(Level.FINE)) { LOGGER.log( Level.FINE, "Client State: total number of characters written: {0}", bos.getTotalCharsWritten()); } } finally { if (oos != null) { try { oos.close(); } catch (IOException ioe) { // ignore } } } }
public Game(boolean host) { try { if (host) { System.out.println("Hosting..."); server = new ServerSocket(port, 4, InetAddress.getByName(serverIP)); System.out.println("Ready!\nAwaiting client..."); client = server.accept(); System.out.println("Client connected!\nBuffering..."); out = new ObjectOutputStream(client.getOutputStream()); in = new ObjectInputStream(client.getInputStream()); System.out.println("Buffered!\nPinging for 256 bytes..."); long start = System.currentTimeMillis(); byte[] ping = new byte[256]; in.read(ping); System.out.println("Latency: " + (System.currentTimeMillis() - start)); out.writeLong(start); out.flush(); System.out.println("Starting threads..."); new ThreadSend(world, out); new ThreadReceive(world, in); System.out.println("Started!\nCreating game world..."); } else { System.out.println("Connecting..."); socket = new Socket(connectIP, port); System.out.println("Connected!\nBuffering..."); in = new ObjectInputStream(socket.getInputStream()); out = new ObjectOutputStream(socket.getOutputStream()); byte[] ping = new byte[256]; new Random().nextBytes(ping); System.out.println("Buffered\nPinging for 256 bytes..."); out.write(ping); out.flush(); long latency = in.readLong(); System.out.println("Latency: " + (System.currentTimeMillis() - latency)); System.out.println("Starting threads..."); new ThreadReceive(world, in); new ThreadSend(world, out); System.out.println("Started!\nCreating game world..."); } } catch (Exception e) { e.printStackTrace(); } try { Display.setDisplayMode(new DisplayMode(width, height)); Display.create(); } catch (Exception e) { e.printStackTrace(); } world.init(); while (!Display.isCloseRequested()) { if (ended) break; world.update(); } Display.destroy(); }
public boolean execute(long val) { try { stream.writeLong(val); } catch (IOException e) { this.exception = e; return false; } return true; }
private void writeObject(ObjectOutputStream out) throws IOException { out.writeUTF(m_title); out.writeUTF(m_imageLink); out.writeUTF(m_imageName); out.writeUTF(m_urlTrimmed); out.writeUTF(m_url); out.writeUTF(m_content); out.writeObject(m_desLines); out.writeLong(m_time); }
public boolean execute(long key, float val) { try { stream.writeLong(key); stream.writeFloat(val); } catch (IOException e) { this.exception = e; return false; } return true; }
public synchronized void saveIndex() { try { ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(getHeaderIdFilePath())); oos.writeLong(allowedSpace); oos.writeInt(headerIds.size()); for (int i = 0; i < headerIds.size(); i++) { oos.writeLong(headerIds.get(i)); } oos.writeInt(transactionIds.size()); for (int i = 0; i < transactionIds.size(); i++) { oos.writeLong(transactionIds.get(i)); } oos.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
private void writeObject(java.io.ObjectOutputStream s) throws java.io.IOException { final long key[] = this.key; final float value[] = this.value; final MapIterator i = new MapIterator(); s.defaultWriteObject(); for (int j = size, e; j-- != 0; ) { e = i.nextEntry(); s.writeLong(key[e]); s.writeFloat(value[e]); } }
/* */ private void writeObject(ObjectOutputStream s) throws IOException { /* 1284 */ long[] key = this.key; /* 1285 */ short[] value = this.value; /* 1286 */ MapIterator i = new MapIterator(null); /* 1287 */ s.defaultWriteObject(); /* 1288 */ for (int j = this.size; j-- != 0; ) { /* 1289 */ int e = i.nextEntry(); /* 1290 */ s.writeLong(key[e]); /* 1291 */ s.writeShort(value[e]); /* */ } /* */ }
/* */ private void writeObject(ObjectOutputStream s) throws IOException { /* 791 */ long[] key = this.key; /* 792 */ boolean[] value = this.value; /* 793 */ MapIterator i = new MapIterator(null); /* 794 */ s.defaultWriteObject(); /* 795 */ for (int j = this.size; j-- != 0; ) { /* 796 */ int e = i.nextEntry(); /* 797 */ s.writeLong(key[e]); /* 798 */ s.writeBoolean(value[e]); /* */ } /* */ }
/* */ private void writeObject(ObjectOutputStream s) throws IOException { /* 800 */ long[] key = this.key; /* 801 */ byte[] value = this.value; /* 802 */ MapIterator i = new MapIterator(null); /* 803 */ s.defaultWriteObject(); /* 804 */ for (int j = this.size; j-- != 0; ) { /* 805 */ int e = i.nextEntry(); /* 806 */ s.writeLong(key[e]); /* 807 */ s.writeByte(value[e]); /* */ } /* */ }
// inherit doc comment public void store(ObjectOutputStream out) throws IOException { final long bits0; final long bits1; if (id == null) { bits0 = 0; bits1 = 0; } else { bits0 = id.getMostSignificantBits(); bits1 = id.getLeastSignificantBits(); } out.writeLong(bits0); out.writeLong(bits1); out.writeLong(expires); out.writeObject(codebase); out.writeObject(className); out.writeObject(superclasses); out.writeObject(values); out.writeLong(hash); out.writeObject(hashes); }
private void writeObject(ObjectOutputStream out) throws IOException { out.writeUTF(localPath.getName()); out.writeLong(localPath.length()); byte[] xfer = new byte[4096]; FileInputStream fis = new FileInputStream(localPath); try { for (int read = fis.read(xfer); read >= 0; read = fis.read(xfer)) out.write(xfer, 0, read); } finally { fis.close(); } }
public boolean a_(OutputStream outputStream) { boolean z = true; boolean z2 = false; try { ObjectOutputStream objectOutputStream = new ObjectOutputStream(outputStream); objectOutputStream.writeByte(GoogleScorer.CLIENT_PLUS); objectOutputStream.writeUTF(this.b); objectOutputStream.writeUTF(this.c == null ? AdTrackerConstants.BLANK : this.c); objectOutputStream.writeLong(this.d); objectOutputStream.writeLong(this.e); objectOutputStream.writeLong(this.f); a(this.g, objectOutputStream); objectOutputStream.flush(); return z; } catch (IOException e) { String str = "%s"; Object[] objArr = new Object[z]; objArr[z2] = e.toString(); t.b(str, objArr); return z2; } }
private void writeObject(ObjectOutputStream out) throws IOException { synchronized (cache) { synchronized (commands) { out.writeObject(name); // cache and commands are never null out.writeLong(System.currentTimeMillis()); out.writeObject(myContribution); out.writeInt(cache.size()); Iterator i = cache.values().iterator(); while (i.hasNext()) out.writeObject(i.next()); out.writeInt(commands.size()); i = commands.entrySet().iterator(); while (i.hasNext()) { Map.Entry e = (Map.Entry) i.next(); long time = ((Long) e.getValue()).longValue(); out.writeObject(e.getKey()); out.writeLong(time); } } } }
/** 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.writeLong(0); } oout.flush(); for (int j = 0; j < ncycles; j++) { oin.readLong(); } } }
/* * When object is serialized writeReplace() causes this * SerializationProxy object to be written. Write it in a * custom way that includes a version ID so that clients * and servers can have two different versions of code. */ private void writeObject(java.io.ObjectOutputStream stream) throws IOException { stream.writeShort(serializationVersion); stream.writeObject(vehicleId); stream.writeLong(time); stream.writeFloat(latitude); stream.writeFloat(longitude); stream.writeFloat(speed); stream.writeFloat(heading); stream.writeObject(source); stream.writeObject(assignmentId); stream.writeObject(assignmentType); stream.writeObject(driverId); stream.writeObject(licensePlate); stream.writeInt(passengerCount); }
/* * When object is serialized writeReplace() causes this * SerializationProxy object to be written. Write it in a custom way * that includes a version ID so that clients and servers can have two * different versions of code. */ protected void writeObject(java.io.ObjectOutputStream stream) throws IOException { stream.writeShort(currentSerializationVersion); stream.writeObject(blockId); stream.writeObject(blockAssignmentMethod); stream.writeObject(avl); stream.writeFloat(heading); stream.writeObject(routeId); stream.writeObject(routeShortName); stream.writeObject(tripId); stream.writeObject(tripPatternId); stream.writeObject(directionId); stream.writeObject(headsign); stream.writeBoolean(predictable); stream.writeBoolean(schedBasedPred); stream.writeObject(realTimeSchdAdh); stream.writeBoolean(isDelayed); stream.writeBoolean(isLayover); stream.writeLong(layoverDepartureTime); stream.writeObject(nextStopId); stream.writeObject(nextStopName); stream.writeObject(vehicleType); }
public static void writePropagationContext(MarshallerWriteContext context, PropagationContext pc) throws IOException { ObjectOutputStream stream = context.stream; Map<LeftTuple, Integer> tuples = context.terminalTupleMap; stream.writeInt(pc.getType()); Rule ruleOrigin = pc.getRuleOrigin(); if (ruleOrigin != null) { stream.writeBoolean(true); stream.writeUTF(ruleOrigin.getPackage()); stream.writeUTF(ruleOrigin.getName()); } else { stream.writeBoolean(false); } LeftTuple tupleOrigin = pc.getLeftTupleOrigin(); if (tupleOrigin != null && tuples.containsKey(tupleOrigin)) { stream.writeBoolean(true); stream.writeInt(tuples.get(tupleOrigin)); } else { stream.writeBoolean(false); } stream.writeLong(pc.getPropagationNumber()); if (pc.getFactHandleOrigin() != null) { stream.writeInt(((InternalFactHandle) pc.getFactHandleOrigin()).getId()); } else { stream.writeInt(-1); } stream.writeInt(pc.getActiveActivations()); stream.writeInt(pc.getDormantActivations()); stream.writeUTF(pc.getEntryPoint().getEntryPointId()); }
@Override public void writeLong(long val) throws IOException { out.writeLong(val); }
public static void writeLeftTuple( LeftTuple leftTuple, MarshallerWriteContext context, boolean recurse) throws IOException { ObjectOutputStream stream = context.stream; InternalRuleBase ruleBase = context.ruleBase; InternalWorkingMemory wm = context.wm; LeftTupleSink sink = leftTuple.getLeftTupleSink(); switch (sink.getType()) { case NodeTypeEnums.JoinNode: { // context.out.println( "JoinNode" ); for (LeftTuple childLeftTuple = leftTuple.getFirstChild(); childLeftTuple != null; childLeftTuple = (LeftTuple) childLeftTuple.getLeftParentNext()) { stream.writeShort(PersisterEnums.RIGHT_TUPLE); int childSinkId = childLeftTuple.getLeftTupleSink().getId(); stream.writeInt(childSinkId); stream.writeInt(childLeftTuple.getRightParent().getFactHandle().getId()); // context.out.println( "RightTuple int:" + childLeftTuple.getLeftTupleSink().getId() + // " int:" + childLeftTuple.getRightParent().getFactHandle().getId() ); writeLeftTuple(childLeftTuple, context, recurse); } stream.writeShort(PersisterEnums.END); // context.out.println( "JoinNode --- END" ); break; } case NodeTypeEnums.QueryRiaFixerNode: case NodeTypeEnums.EvalConditionNode: { // context.out.println( ".... EvalConditionNode" ); for (LeftTuple childLeftTuple = leftTuple.getFirstChild(); childLeftTuple != null; childLeftTuple = (LeftTuple) childLeftTuple.getLeftParentNext()) { stream.writeShort(PersisterEnums.LEFT_TUPLE); stream.writeInt(childLeftTuple.getLeftTupleSink().getId()); writeLeftTuple(childLeftTuple, context, recurse); } stream.writeShort(PersisterEnums.END); // context.out.println( "---- EvalConditionNode --- END" ); break; } case NodeTypeEnums.NotNode: case NodeTypeEnums.ForallNotNode: { if (leftTuple.getBlocker() == null) { // is not blocked so has children stream.writeShort(PersisterEnums.LEFT_TUPLE_NOT_BLOCKED); for (LeftTuple childLeftTuple = leftTuple.getFirstChild(); childLeftTuple != null; childLeftTuple = (LeftTuple) childLeftTuple.getLeftParentNext()) { stream.writeShort(PersisterEnums.LEFT_TUPLE); stream.writeInt(childLeftTuple.getLeftTupleSink().getId()); writeLeftTuple(childLeftTuple, context, recurse); } stream.writeShort(PersisterEnums.END); } else { stream.writeShort(PersisterEnums.LEFT_TUPLE_BLOCKED); stream.writeInt(leftTuple.getBlocker().getFactHandle().getId()); } break; } case NodeTypeEnums.ExistsNode: { if (leftTuple.getBlocker() == null) { // is blocked so has children stream.writeShort(PersisterEnums.LEFT_TUPLE_NOT_BLOCKED); } else { stream.writeShort(PersisterEnums.LEFT_TUPLE_BLOCKED); stream.writeInt(leftTuple.getBlocker().getFactHandle().getId()); for (LeftTuple childLeftTuple = leftTuple.getFirstChild(); childLeftTuple != null; childLeftTuple = (LeftTuple) childLeftTuple.getLeftParentNext()) { stream.writeShort(PersisterEnums.LEFT_TUPLE); stream.writeInt(childLeftTuple.getLeftTupleSink().getId()); writeLeftTuple(childLeftTuple, context, recurse); } stream.writeShort(PersisterEnums.END); } break; } case NodeTypeEnums.AccumulateNode: { // context.out.println( ".... AccumulateNode" ); // accumulate nodes generate new facts on-demand and need special procedures when // serializing to persistent storage AccumulateMemory memory = (AccumulateMemory) context.wm.getNodeMemory((BetaNode) sink); AccumulateContext accctx = (AccumulateContext) leftTuple.getObject(); // first we serialize the generated fact handle writeFactHandle( context, stream, context.objectMarshallingStrategyStore, accctx.result.getFactHandle()); // then we serialize the associated accumulation context stream.writeObject(accctx.context); // then we serialize the boolean propagated flag stream.writeBoolean(accctx.propagated); // then we serialize all the propagated tuples for (LeftTuple childLeftTuple = leftTuple.getFirstChild(); childLeftTuple != null; childLeftTuple = (LeftTuple) childLeftTuple.getLeftParentNext()) { if (leftTuple.getLeftTupleSink().getId() == childLeftTuple.getLeftTupleSink().getId()) { // this is a matching record, so, associate the right tuples // context.out.println( "RightTuple(match) int:" + // childLeftTuple.getLeftTupleSink().getId() + " int:" + // childLeftTuple.getRightParent().getFactHandle().getId() ); stream.writeShort(PersisterEnums.RIGHT_TUPLE); stream.writeInt(childLeftTuple.getRightParent().getFactHandle().getId()); } else { // this is a propagation record // context.out.println( "RightTuple(propagation) int:" + // childLeftTuple.getLeftTupleSink().getId() + " int:" + // childLeftTuple.getRightParent().getFactHandle().getId() ); stream.writeShort(PersisterEnums.LEFT_TUPLE); int sinkId = childLeftTuple.getLeftTupleSink().getId(); stream.writeInt(sinkId); writeLeftTuple(childLeftTuple, context, recurse); } } stream.writeShort(PersisterEnums.END); // context.out.println( "---- AccumulateNode --- END" ); break; } case NodeTypeEnums.RightInputAdaterNode: { // context.out.println( ".... RightInputAdapterNode" ); // RIANs generate new fact handles on-demand to wrap tuples and need special procedures // when serializing to persistent storage ObjectHashMap memory = (ObjectHashMap) context.wm.getNodeMemory((NodeMemory) sink); InternalFactHandle ifh = (InternalFactHandle) memory.get(leftTuple); // first we serialize the generated fact handle ID // context.out.println( "FactHandle id:"+ifh.getId() ); stream.writeInt(ifh.getId()); stream.writeLong(ifh.getRecency()); writeRightTuples(ifh, context); stream.writeShort(PersisterEnums.END); // context.out.println( "---- RightInputAdapterNode --- 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); Map<Object, RightTuple> matches = (Map<Object, RightTuple>) leftTuple.getObject(); for (RightTuple rightTuples : matches.values()) { // first we serialize the generated fact handle ID stream.writeShort(PersisterEnums.FACT_HANDLE); writeFactHandle( context, stream, context.objectMarshallingStrategyStore, rightTuples.getFactHandle()); writeRightTuples(rightTuples.getFactHandle(), context); } stream.writeShort(PersisterEnums.END); for (LeftTuple childLeftTuple = leftTuple.getFirstChild(); childLeftTuple != null; childLeftTuple = (LeftTuple) childLeftTuple.getLeftParentNext()) { stream.writeShort(PersisterEnums.RIGHT_TUPLE); stream.writeInt(childLeftTuple.getLeftTupleSink().getId()); stream.writeInt(childLeftTuple.getRightParent().getFactHandle().getId()); // context.out.println( "RightTuple int:" + childLeftTuple.getLeftTupleSink().getId() + // " int:" + childLeftTuple.getRightParent().getFactHandle().getId() ); writeLeftTuple(childLeftTuple, context, recurse); } stream.writeShort(PersisterEnums.END); // context.out.println( "---- FromNode --- END" ); break; } case NodeTypeEnums.UnificationNode: { // context.out.println( ".... UnificationNode" ); QueryElementNode node = (QueryElementNode) sink; boolean isOpen = node.isOpenQuery(); context.writeBoolean(isOpen); if (isOpen) { InternalFactHandle factHandle = (InternalFactHandle) leftTuple.getObject(); DroolsQuery query = (DroolsQuery) factHandle.getObject(); // context.out.println( "factHandle:" + factHandle ); factHandle.setObject(null); writeFactHandle(context, stream, context.objectMarshallingStrategyStore, 0, factHandle); factHandle.setObject(query); writeLeftTuples(context, new InternalFactHandle[] {factHandle}); } else { for (LeftTuple childLeftTuple = leftTuple.getFirstChild(); childLeftTuple != null; childLeftTuple = (LeftTuple) childLeftTuple.getLeftParentNext()) { stream.writeShort(PersisterEnums.LEFT_TUPLE); stream.writeInt(childLeftTuple.getLeftTupleSink().getId()); InternalFactHandle factHandle = childLeftTuple.getLastHandle(); writeFactHandle( context, stream, context.objectMarshallingStrategyStore, 1, factHandle); writeLeftTuple(childLeftTuple, context, recurse); } stream.writeShort(PersisterEnums.END); } // context.out.println( "---- EvalConditionNode --- END" ); break; } case NodeTypeEnums.RuleTerminalNode: { // context.out.println( "RuleTerminalNode" ); int pos = context.terminalTupleMap.size(); context.terminalTupleMap.put(leftTuple, pos); break; } case NodeTypeEnums.QueryTerminalNode: { // context.out.println( ".... QueryTerminalNode" ); // LeftTuple entry = leftTuple; // // // find the DroolsQuery object // while ( entry.getParent() != null ) { // entry = entry.getParent(); // } // // // Now output all the child tuples in the caller network // DroolsQuery query = (DroolsQuery) entry.getLastHandle().getObject(); // if ( query.getQueryResultCollector() instanceof // UnificationNodeViewChangedEventListener ) { // context.writeBoolean( true ); // UnificationNodeViewChangedEventListener collector = // (UnificationNodeViewChangedEventListener) query.getQueryResultCollector(); // leftTuple = collector.getLeftTuple(); // context.writeBoolean(true); RightTuple rightTuple = (RightTuple) leftTuple.getObject(); // context.out.println( "rightTuple:" + rightTuple.getFactHandle() ); writeFactHandle( context, stream, context.objectMarshallingStrategyStore, 1, rightTuple.getFactHandle()); for (LeftTuple childLeftTuple = rightTuple.firstChild; childLeftTuple != null; childLeftTuple = (LeftTuple) childLeftTuple.getRightParentNext()) { stream.writeShort(PersisterEnums.LEFT_TUPLE); stream.writeInt(childLeftTuple.getLeftTupleSink().getId()); writeLeftTuple(childLeftTuple, context, recurse); } // for ( LeftTuple childLeftTuple = leftTuple.getFirstChild(); // childLeftTuple != null; childLeftTuple = (LeftTuple) childLeftTuple.getLeftParentNext() // ) { // stream.writeShort( PersisterEnums.LEFT_TUPLE ); // stream.writeInt( childLeftTuple.getLeftTupleSink().getId() ); // writeFactHandle( context, // stream, // context.objectMarshallingStrategyStore, // 1, // childLeftTuple.getLastHandle() ); // writeLeftTuple( childLeftTuple, // context, // recurse ); // } // } else { // context.writeBoolean( false ); // } stream.writeShort(PersisterEnums.END); // context.out.println( "---- QueryTerminalNode --- END" ); break; } } }
@Override public void writeObjectData(java.io.ObjectOutputStream out) throws IOException { super.writeObjectData(out); out.writeLong(this.getCreationTime()); }
@Override public void write(ObjectOutputStream out) throws IOException { out.writeLong(this.localValue); }