Example usage for java.io ObjectOutputStream writeBoolean

List of usage examples for java.io ObjectOutputStream writeBoolean

Introduction

In this page you can find the example usage for java.io ObjectOutputStream writeBoolean.

Prototype

public void writeBoolean(boolean val) throws IOException 

Source Link

Document

Writes a boolean.

Usage

From source file:bftsmart.tom.core.Synchronizer.java

private void startSynchronization(int nextReg) {

    boolean condition;
    ObjectOutputStream out = null;
    ByteArrayOutputStream bos = null;

    if (this.controller.getStaticConf().isBFT()) {
        condition = lcManager.getStopsSize(nextReg) > this.controller.getCurrentViewF();
    } else {/*  w ww. j  a  va 2 s.c  om*/
        condition = lcManager.getStopsSize(nextReg) > 0;
    }

    // Ask to start the synchronizations phase if enough messages have been received already
    if (condition && lcManager.getNextReg() == lcManager.getLastReg()) {

        Logger.println("(Synchronizer.startSynchronization) initialize synch phase");
        requestsTimer.Enabled(false);
        requestsTimer.stopTimer();

        lcManager.setNextReg(lcManager.getLastReg() + 1); // define next timestamp

        int regency = lcManager.getNextReg();

        // store information about message I am going to send
        lcManager.addStop(regency, this.controller.getStaticConf().getProcessId());

        //execManager.stop(); // stop execution of consensus

        //Get requests that timed out and the requests received in STOP messages
        //and add those STOPed requests to the client manager
        addSTOPedRequestsToClientManager();
        List<TOMMessage> messages = getRequestsToRelay();

        try { // serialize conent to send in the STOP message
            bos = new ByteArrayOutputStream();
            out = new ObjectOutputStream(bos);

            // Do I have messages to send in the STOP message?
            if (messages != null && messages.size() > 0) {

                //TODO: If this is null, there was no timeout nor STOP messages.
                //What shall be done then?
                out.writeBoolean(true);
                byte[] serialized = bb.makeBatch(messages, 0, 0, controller);
                out.writeObject(serialized);
            } else {
                out.writeBoolean(false);
                System.out.println(
                        "(Synchronizer.startSynchronization) Strange... did not include any request in my STOP message for regency "
                                + regency);
            }

            out.flush();
            bos.flush();

            byte[] payload = bos.toByteArray();
            out.close();
            bos.close();

            // send message STOP
            System.out.println("(Synchronizer.startSynchronization) sending STOP message to install regency "
                    + regency + " with " + (messages != null ? messages.size() : 0) + " request(s) to relay");

            LCMessage stop = new LCMessage(this.controller.getStaticConf().getProcessId(), TOMUtil.STOP,
                    regency, payload);
            requestsTimer.setSTOP(regency, stop); // make replica re-transmit the stop message until a new regency is installed
            communication.send(this.controller.getCurrentViewOtherAcceptors(), stop);

        } catch (IOException ex) {
            ex.printStackTrace();
            java.util.logging.Logger.getLogger(TOMLayer.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            try {
                out.close();
                bos.close();
            } catch (IOException ex) {
                ex.printStackTrace();
                java.util.logging.Logger.getLogger(TOMLayer.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }

    if (this.controller.getStaticConf().isBFT()) {
        condition = lcManager.getStopsSize(nextReg) > (2 * this.controller.getCurrentViewF());
    } else {
        condition = lcManager.getStopsSize(nextReg) > this.controller.getCurrentViewF();
    }

    // Did the synchronization phase really started?
    //if (lcManager.getStopsSize(nextReg) > this.reconfManager.getQuorum2F() && lcManager.getNextReg() > lcManager.getLastReg()) {
    if (condition && lcManager.getNextReg() > lcManager.getLastReg()) {

        if (!execManager.stopped())
            execManager.stop(); // stop consensus execution if more than f replicas sent a STOP message

        Logger.println("(Synchronizer.startSynchronization) installing regency " + lcManager.getNextReg());
        lcManager.setLastReg(lcManager.getNextReg()); // define last timestamp

        int regency = lcManager.getLastReg();

        // avoid memory leaks
        lcManager.removeStops(nextReg);
        lcManager.clearCurrentRequestTimedOut();
        lcManager.clearRequestsFromSTOP();

        requestsTimer.Enabled(true);
        requestsTimer.setShortTimeout(-1);
        requestsTimer.startTimer();

        //int leader = regency % this.reconfManager.getCurrentViewN(); // new leader
        int leader = lcManager.getNewLeader();
        int in = tom.getInExec(); // cid to execute
        int last = tom.getLastExec(); // last cid decided

        execManager.setNewLeader(leader);

        // If I am not the leader, I have to send a STOPDATA message to the elected leader
        if (leader != this.controller.getStaticConf().getProcessId()) {

            try { // serialize content of the STOPDATA message

                bos = new ByteArrayOutputStream();
                out = new ObjectOutputStream(bos);

                Consensus cons = null;

                // content of the last decided CID
                if (last > -1)
                    cons = execManager.getConsensus(last);

                //Do I have info on my last executed consensus?
                if (cons != null && cons.getDecisionEpoch() != null
                        && cons.getDecisionEpoch().propValue != null) {

                    out.writeBoolean(true);
                    out.writeInt(last);
                    //byte[] decision = exec.getLearner().getDecision();

                    byte[] decision = cons.getDecisionEpoch().propValue;
                    Set<ConsensusMessage> proof = cons.getDecisionEpoch().getProof();

                    out.writeObject(decision);
                    out.writeObject(proof);
                    // TODO: WILL BE NECESSARY TO ADD A PROOF!!!

                } else {
                    out.writeBoolean(false);

                    ////// THIS IS TO CATCH A BUG!!!!!
                    if (last > -1) {
                        System.out.println("[DEBUG INFO FOR LAST CID #1]");

                        if (cons == null) {
                            if (last > -1)
                                System.out.println("No consensus instance for cid " + last);

                        } else if (cons.getDecisionEpoch() == null) {
                            System.out.println("No decision epoch for cid " + last);
                        } else {
                            System.out.println(
                                    "epoch for cid: " + last + ": " + cons.getDecisionEpoch().toString());

                            if (cons.getDecisionEpoch().propValue == null) {
                                System.out.println("No propose for cid " + last);
                            } else {
                                System.out.println(
                                        "Propose hash for cid " + last + ": " + Base64.encodeBase64String(
                                                tom.computeHash(cons.getDecisionEpoch().propValue)));
                            }
                        }
                    }

                }

                if (in > -1) { // content of cid in execution

                    cons = execManager.getConsensus(in);

                    //cons.incEts(); // make the consensus advance to the next epoch
                    cons.setETS(regency); // make the consensus advance to the next epoch

                    //int ets = cons.getEts();
                    //cons.createEpoch(ets, controller);
                    cons.createEpoch(regency, controller);
                    //Logger.println("(Synchronizer.startSynchronization) incrementing ets of consensus " + cons.getId() + " to " + ets);
                    Logger.println("(Synchronizer.startSynchronization) incrementing ets of consensus "
                            + cons.getId() + " to " + regency);

                    TimestampValuePair quorumWrites;
                    if (cons.getQuorumWrites() != null) {

                        quorumWrites = cons.getQuorumWrites();

                    } else {

                        quorumWrites = new TimestampValuePair(0, new byte[0]);
                    }

                    HashSet<TimestampValuePair> writeSet = cons.getWriteSet();

                    //CollectData collect = new CollectData(this.controller.getStaticConf().getProcessId(), in, ets, quorumWrites, writeSet);
                    CollectData collect = new CollectData(this.controller.getStaticConf().getProcessId(), in,
                            regency, quorumWrites, writeSet);

                    SignedObject signedCollect = tom.sign(collect);

                    out.writeObject(signedCollect);

                } else {

                    cons = execManager.getConsensus(last + 1);

                    //cons.incEts(); // make the consensus advance to the next epoch
                    cons.setETS(regency); // make the consensus advance to the next epoch

                    //int ets = cons.getEts();
                    //cons.createEpoch(ets, controller);
                    cons.createEpoch(regency, controller);
                    //Logger.println("(Synchronizer.startSynchronization) incrementing ets of consensus " + cons.getId() + " to " + ets);
                    Logger.println("(Synchronizer.startSynchronization) incrementing ets of consensus "
                            + cons.getId() + " to " + regency);

                    //CollectData collect = new CollectData(this.controller.getStaticConf().getProcessId(), last + 1, ets, new TimestampValuePair(0, new byte[0]), new HashSet<TimestampValuePair>());
                    CollectData collect = new CollectData(this.controller.getStaticConf().getProcessId(),
                            last + 1, regency, new TimestampValuePair(0, new byte[0]),
                            new HashSet<TimestampValuePair>());

                    SignedObject signedCollect = tom.sign(collect);

                    out.writeObject(signedCollect);

                }

                out.flush();
                bos.flush();

                byte[] payload = bos.toByteArray();
                out.close();
                bos.close();

                int[] b = new int[1];
                b[0] = leader;

                System.out
                        .println("(Synchronizer.startSynchronization) sending STOPDATA of regency " + regency);
                // send message SYNC to the new leader
                communication.send(b, new LCMessage(this.controller.getStaticConf().getProcessId(),
                        TOMUtil.STOPDATA, regency, payload));

                //TODO: Turn on timeout again?
            } catch (IOException ex) {
                ex.printStackTrace();
                java.util.logging.Logger.getLogger(TOMLayer.class.getName()).log(Level.SEVERE, null, ex);
            } finally {
                try {
                    out.close();
                    bos.close();
                } catch (IOException ex) {
                    ex.printStackTrace();
                    java.util.logging.Logger.getLogger(TOMLayer.class.getName()).log(Level.SEVERE, null, ex);
                }
            }

            // the replica might have received a SYNC that was out of context at the time it was received, but now can be processed
            Set<LCMessage> sync = getOutOfContextLC(TOMUtil.SYNC, regency);

            Logger.println(
                    "(Synchronizer.startSynchronization) Checking if there are out of context SYNC for regency "
                            + regency);

            if (sync.size() > 0) {
                System.out.println(
                        "(Synchronizer.startSynchronization) Processing out of context SYNC for regency "
                                + regency);
            } else {
                Logger.println(
                        "(Synchronizer.startSynchronization) No out of context SYNC for regency " + regency);
            }

            for (LCMessage m : sync) {
                if (m.getSender() == execManager.getCurrentLeader()) {
                    processSYNC(m.getPayload(), regency);
                    return; // makes no sense to continue, since there is only one SYNC message
                }
            }

        } else { // If leader, I will store information that I would send in a SYNC message

            Logger.println("(Synchronizer.startSynchronization) I'm the leader for this new regency");
            CertifiedDecision lastDec = null;
            CollectData collect = null;

            Consensus cons = null;

            //Content of the last decided CID
            if (last > -1)
                cons = execManager.getConsensus(last);

            //Do I have info on my last executed consensus?
            if (cons != null && cons.getDecisionEpoch() != null && cons.getDecisionEpoch().propValue != null) {
                //byte[] decision = exec.getLearner().getDecision();

                byte[] decision = cons.getDecisionEpoch().propValue;
                Set<ConsensusMessage> proof = cons.getDecisionEpoch().getProof();

                lastDec = new CertifiedDecision(this.controller.getStaticConf().getProcessId(), last, decision,
                        proof);
                // TODO: WILL BE NECESSARY TO ADD A PROOF!!!??

            } else {
                lastDec = new CertifiedDecision(this.controller.getStaticConf().getProcessId(), last, null,
                        null);

                ////// THIS IS TO CATCH A BUG!!!!!
                if (last > -1) {
                    System.out.println("[DEBUG INFO FOR LAST CID #2]");

                    if (cons == null) {
                        if (last > -1)
                            System.out.println("No consensus instance for cid " + last);

                    } else if (cons.getDecisionEpoch() == null) {
                        System.out.println("No decision epoch for cid " + last);
                    } else {
                        System.out
                                .println("epoch for cid: " + last + ": " + cons.getDecisionEpoch().toString());
                    }
                    if (cons.getDecisionEpoch().propValue == null) {
                        System.out.println("No propose for cid " + last);
                    } else {
                        System.out.println("Propose hash for cid " + last + ": " + Base64
                                .encodeBase64String(tom.computeHash(cons.getDecisionEpoch().propValue)));
                    }
                }

            }
            lcManager.addLastCID(regency, lastDec);

            if (in > -1) { // content of cid being executed
                cons = execManager.getConsensus(in);

                //cons.incEts(); // make the consensus advance to the next epoch
                cons.setETS(regency); // make the consensus advance to the next epoch

                //int ets = cons.getEts();
                //cons.createEpoch(ets, controller);
                cons.createEpoch(regency, controller);
                //Logger.println("(Synchronizer.startSynchronization) incrementing ets of consensus " + cons.getId() + " to " + ets);
                Logger.println("(Synchronizer.startSynchronization) incrementing ets of consensus "
                        + cons.getId() + " to " + regency);

                TimestampValuePair quorumWrites;

                if (cons.getQuorumWrites() != null) {

                    quorumWrites = cons.getQuorumWrites();
                } else {
                    quorumWrites = new TimestampValuePair(0, new byte[0]);
                }

                HashSet<TimestampValuePair> writeSet = cons.getWriteSet();

                //collect = new CollectData(this.controller.getStaticConf().getProcessId(), in, ets, quorumWrites, writeSet);
                collect = new CollectData(this.controller.getStaticConf().getProcessId(), in, regency,
                        quorumWrites, writeSet);

            } else {

                cons = execManager.getConsensus(last + 1);

                //cons.incEts(); // make the consensus advance to the next epoch
                cons.setETS(regency); // make the consensus advance to the next epoch

                //int ets = cons.getEts();
                //cons.createEpoch(ets, controller);
                cons.createEpoch(regency, controller);
                //Logger.println("(Synchronizer.startSynchronization) incrementing ets of consensus " + cons.getId() + " to " + ets);
                Logger.println("(Synchronizer.startSynchronization) incrementing ets of consensus "
                        + cons.getId() + " to " + regency);

                //collect = new CollectData(this.controller.getStaticConf().getProcessId(), last + 1, ets, new TimestampValuePair(0, new byte[0]), new HashSet<TimestampValuePair>());
                collect = new CollectData(this.controller.getStaticConf().getProcessId(), last + 1, regency,
                        new TimestampValuePair(0, new byte[0]), new HashSet<TimestampValuePair>());
            }

            SignedObject signedCollect = tom.sign(collect);

            lcManager.addCollect(regency, signedCollect);

            // the replica might have received STOPDATAs that were out of context at the time they were received, but now can be processed
            Set<LCMessage> stopdatas = getOutOfContextLC(TOMUtil.STOPDATA, regency);

            Logger.println(
                    "(Synchronizer.startSynchronization) Checking if there are out of context STOPDATAs for regency "
                            + regency);
            if (stopdatas.size() > 0) {
                System.out.println("(Synchronizer.startSynchronization) Processing " + stopdatas.size()
                        + " out of context STOPDATAs for regency " + regency);
            } else {
                Logger.println("(Synchronizer.startSynchronization) No out of context STOPDATAs for regency "
                        + regency);
            }

            for (LCMessage m : stopdatas) {
                processSTOPDATA(m, regency);
            }

        }

    }
}

From source file:no.sesat.search.datamodel.BeanDataObjectInvocationHandler.java

private void writeObject(ObjectOutputStream stream) throws IOException {
    stream.writeObject(implementOf);//from   w w  w .j ava  2  s  .  co  m
    stream.writeObject(context);
    stream.writeObject(support);
    stream.writeBoolean(immutable);
    stream.writeObject(properties);
}

From source file:org.apache.axis.message.RPCParam.java

private void writeObject(ObjectOutputStream out) throws IOException {
    if (getQName() == null) {
        out.writeBoolean(false);
    } else {/*from  www. j a va2 s .com*/
        out.writeBoolean(true);
        out.writeObject(getQName().getNamespaceURI());
        out.writeObject(getQName().getLocalPart());
    }
    out.defaultWriteObject();
}

From source file:org.apache.lens.driver.hive.TestRemoteHiveDriver.java

/**
 * Persist context./*from  www . java 2s . c  o  m*/
 *
 * @param ctx the ctx
 * @return the byte[]
 * @throws IOException Signals that an I/O exception has occurred.
 */
private byte[] persistContext(QueryContext ctx) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream out = new ObjectOutputStream(baos);
    try {
        out.writeObject(ctx);
        boolean isDriverAvailable = (ctx.getSelectedDriver() != null);
        out.writeBoolean(isDriverAvailable);
        if (isDriverAvailable) {
            out.writeUTF(ctx.getSelectedDriver().getFullyQualifiedName());
        }
    } finally {
        out.flush();
        out.close();
        baos.close();
    }

    return baos.toByteArray();
}

From source file:org.bigtextml.topics.ParallelTopicModel.java

private void writeObject(ObjectOutputStream out) throws IOException {
    out.writeInt(CURRENT_SERIAL_VERSION);

    //This part needs to be re-written
    /*/*w  w  w.  j  a  v  a  2 s .co  m*/
    out.writeObject(data);
    out.writeObject(alphabet);
    out.writeObject(topicAlphabet);
    */

    out.writeObject(data);
    out.writeObject(alphabet);
    out.writeObject(topicAlphabet);

    out.writeInt(numTopics);

    out.writeInt(topicMask);
    out.writeInt(topicBits);

    out.writeInt(numTypes);

    out.writeObject(alpha);
    out.writeDouble(alphaSum);
    out.writeDouble(beta);
    out.writeDouble(betaSum);

    out.writeObject(typeTopicCounts);
    out.writeObject(tokensPerTopic);

    out.writeObject(docLengthCounts);
    out.writeObject(topicDocCounts);

    out.writeInt(numIterations);
    out.writeInt(burninPeriod);
    out.writeInt(saveSampleInterval);
    out.writeInt(optimizeInterval);
    out.writeInt(showTopicsInterval);
    out.writeInt(wordsPerTopic);

    out.writeInt(saveStateInterval);
    out.writeObject(stateFilename);

    out.writeInt(saveModelInterval);
    out.writeObject(modelFilename);

    out.writeInt(randomSeed);
    out.writeObject(formatter);
    out.writeBoolean(printLogLikelihood);

    out.writeInt(numThreads);
}

From source file:org.hibernate.engine.internal.StatefulPersistenceContext.java

/**
 * Used by the owning session to explicitly control serialization of the
 * persistence context./* w w w  . j a va2  s. com*/
 *
 * @param oos The stream to which the persistence context should get written
 * @throws IOException serialization errors.
 */
public void serialize(ObjectOutputStream oos) throws IOException {
    LOG.trace("Serializing persistent-context");

    oos.writeBoolean(defaultReadOnly);
    oos.writeBoolean(hasNonReadOnlyEntities);

    oos.writeInt(entitiesByKey.size());
    LOG.trace("Starting serialization of [" + entitiesByKey.size() + "] entitiesByKey entries");
    Iterator itr = entitiesByKey.entrySet().iterator();
    while (itr.hasNext()) {
        Map.Entry entry = (Map.Entry) itr.next();
        ((EntityKey) entry.getKey()).serialize(oos);
        oos.writeObject(entry.getValue());
    }

    oos.writeInt(entitiesByUniqueKey.size());
    LOG.trace("Starting serialization of [" + entitiesByUniqueKey.size() + "] entitiesByUniqueKey entries");
    itr = entitiesByUniqueKey.entrySet().iterator();
    while (itr.hasNext()) {
        Map.Entry entry = (Map.Entry) itr.next();
        ((EntityUniqueKey) entry.getKey()).serialize(oos);
        oos.writeObject(entry.getValue());
    }

    oos.writeInt(proxiesByKey.size());
    LOG.trace("Starting serialization of [" + proxiesByKey.size() + "] proxiesByKey entries");
    itr = proxiesByKey.entrySet().iterator();
    while (itr.hasNext()) {
        Map.Entry entry = (Map.Entry) itr.next();
        ((EntityKey) entry.getKey()).serialize(oos);
        oos.writeObject(entry.getValue());
    }

    oos.writeInt(entitySnapshotsByKey.size());
    LOG.trace("Starting serialization of [" + entitySnapshotsByKey.size() + "] entitySnapshotsByKey entries");
    itr = entitySnapshotsByKey.entrySet().iterator();
    while (itr.hasNext()) {
        Map.Entry entry = (Map.Entry) itr.next();
        ((EntityKey) entry.getKey()).serialize(oos);
        oos.writeObject(entry.getValue());
    }

    oos.writeInt(entityEntries.size());
    LOG.trace("Starting serialization of [" + entityEntries.size() + "] entityEntries entries");
    itr = entityEntries.entrySet().iterator();
    while (itr.hasNext()) {
        Map.Entry entry = (Map.Entry) itr.next();
        oos.writeObject(entry.getKey());
        ((EntityEntry) entry.getValue()).serialize(oos);
    }

    oos.writeInt(collectionsByKey.size());
    LOG.trace("Starting serialization of [" + collectionsByKey.size() + "] collectionsByKey entries");
    itr = collectionsByKey.entrySet().iterator();
    while (itr.hasNext()) {
        Map.Entry entry = (Map.Entry) itr.next();
        ((CollectionKey) entry.getKey()).serialize(oos);
        oos.writeObject(entry.getValue());
    }

    oos.writeInt(collectionEntries.size());
    LOG.trace("Starting serialization of [" + collectionEntries.size() + "] collectionEntries entries");
    itr = collectionEntries.entrySet().iterator();
    while (itr.hasNext()) {
        Map.Entry entry = (Map.Entry) itr.next();
        oos.writeObject(entry.getKey());
        ((CollectionEntry) entry.getValue()).serialize(oos);
    }

    oos.writeInt(arrayHolders.size());
    LOG.trace("Starting serialization of [" + arrayHolders.size() + "] arrayHolders entries");
    itr = arrayHolders.entrySet().iterator();
    while (itr.hasNext()) {
        Map.Entry entry = (Map.Entry) itr.next();
        oos.writeObject(entry.getKey());
        oos.writeObject(entry.getValue());
    }

    oos.writeInt(nullifiableEntityKeys.size());
    LOG.trace("Starting serialization of [" + nullifiableEntityKeys.size() + "] nullifiableEntityKey entries");
    itr = nullifiableEntityKeys.iterator();
    while (itr.hasNext()) {
        EntityKey entry = (EntityKey) itr.next();
        entry.serialize(oos);
    }
}

From source file:org.hibernate.engine.StatefulPersistenceContext.java

/**
 * Used by the owning session to explicitly control serialization of the
 * persistence context.//from  w  w w  . ja  v  a2 s  . com
 *
 * @param oos The stream to which the persistence context should get written
 * @throws IOException serialization errors.
 */
public void serialize(ObjectOutputStream oos) throws IOException {
    log.trace("serializing persistent-context");

    oos.writeBoolean(defaultReadOnly);
    oos.writeBoolean(hasNonReadOnlyEntities);

    oos.writeInt(entitiesByKey.size());
    log.trace("starting serialization of [" + entitiesByKey.size() + "] entitiesByKey entries");
    Iterator itr = entitiesByKey.entrySet().iterator();
    while (itr.hasNext()) {
        Map.Entry entry = (Map.Entry) itr.next();
        ((EntityKey) entry.getKey()).serialize(oos);
        oos.writeObject(entry.getValue());
    }

    oos.writeInt(entitiesByUniqueKey.size());
    log.trace("starting serialization of [" + entitiesByUniqueKey.size() + "] entitiesByUniqueKey entries");
    itr = entitiesByUniqueKey.entrySet().iterator();
    while (itr.hasNext()) {
        Map.Entry entry = (Map.Entry) itr.next();
        ((EntityUniqueKey) entry.getKey()).serialize(oos);
        oos.writeObject(entry.getValue());
    }

    oos.writeInt(proxiesByKey.size());
    log.trace("starting serialization of [" + proxiesByKey.size() + "] proxiesByKey entries");
    itr = proxiesByKey.entrySet().iterator();
    while (itr.hasNext()) {
        Map.Entry entry = (Map.Entry) itr.next();
        ((EntityKey) entry.getKey()).serialize(oos);
        oos.writeObject(entry.getValue());
    }

    oos.writeInt(entitySnapshotsByKey.size());
    log.trace("starting serialization of [" + entitySnapshotsByKey.size() + "] entitySnapshotsByKey entries");
    itr = entitySnapshotsByKey.entrySet().iterator();
    while (itr.hasNext()) {
        Map.Entry entry = (Map.Entry) itr.next();
        ((EntityKey) entry.getKey()).serialize(oos);
        oos.writeObject(entry.getValue());
    }

    oos.writeInt(entityEntries.size());
    log.trace("starting serialization of [" + entityEntries.size() + "] entityEntries entries");
    itr = entityEntries.entrySet().iterator();
    while (itr.hasNext()) {
        Map.Entry entry = (Map.Entry) itr.next();
        oos.writeObject(entry.getKey());
        ((EntityEntry) entry.getValue()).serialize(oos);
    }

    oos.writeInt(collectionsByKey.size());
    log.trace("starting serialization of [" + collectionsByKey.size() + "] collectionsByKey entries");
    itr = collectionsByKey.entrySet().iterator();
    while (itr.hasNext()) {
        Map.Entry entry = (Map.Entry) itr.next();
        ((CollectionKey) entry.getKey()).serialize(oos);
        oos.writeObject(entry.getValue());
    }

    oos.writeInt(collectionEntries.size());
    log.trace("starting serialization of [" + collectionEntries.size() + "] collectionEntries entries");
    itr = collectionEntries.entrySet().iterator();
    while (itr.hasNext()) {
        Map.Entry entry = (Map.Entry) itr.next();
        oos.writeObject(entry.getKey());
        ((CollectionEntry) entry.getValue()).serialize(oos);
    }

    oos.writeInt(arrayHolders.size());
    log.trace("starting serialization of [" + arrayHolders.size() + "] arrayHolders entries");
    itr = arrayHolders.entrySet().iterator();
    while (itr.hasNext()) {
        Map.Entry entry = (Map.Entry) itr.next();
        oos.writeObject(entry.getKey());
        oos.writeObject(entry.getValue());
    }

    oos.writeInt(nullifiableEntityKeys.size());
    log.trace("starting serialization of [" + nullifiableEntityKeys.size() + "] nullifiableEntityKeys entries");
    itr = nullifiableEntityKeys.iterator();
    while (itr.hasNext()) {
        EntityKey entry = (EntityKey) itr.next();
        entry.serialize(oos);
    }
}

From source file:org.jactr.tools.async.message.ast.BaseASTMessage.java

private void writeObject(java.io.ObjectOutputStream out) throws IOException {
    out.defaultWriteObject();/*  w ww  .j  ava 2s  .  com*/
    if (_ast != null) {
        out.writeBoolean(true);
        out.writeBoolean(_compress);

        if (_compress) {
            /*
             * go to a GZIPOutputStream
             */
            ByteArrayOutputStream baos = _localBAOS.get();
            if (baos == null) {
                baos = new ByteArrayOutputStream();
                _localBAOS.set(baos);
            }
            baos.reset();

            DataOutputStream zip = new DataOutputStream(new GZIPOutputStream(baos));
            Serializer.write(_ast, zip);
            zip.flush();
            zip.close();
            // byte[] bytes = baos.toByteArray();

            if (LOGGER.isDebugEnabled())
                LOGGER.debug(String.format("Writing %d compressed bytes", baos.size()));

            out.writeInt(baos.size());
            baos.writeTo(out);

            // if (LOGGER.isDebugEnabled())
            // LOGGER.debug("Compressed AST to "+bytes.length);
            // out.writeInt(bytes.length);
            // out.write(bytes);
        } else
            Serializer.write(_ast, out);
    } else
        out.writeBoolean(false);
}

From source file:org.mule.api.MessagingException.java

private void writeObject(ObjectOutputStream out) throws Exception {
    out.defaultWriteObject();//from   www .  j a  v a2 s . c  o  m
    if (this.failingMessageProcessor instanceof Serializable) {
        out.writeBoolean(true);
        out.writeObject(this.failingMessageProcessor);
    } else {
        out.writeBoolean(false);
    }
}

From source file:org.mule.DefaultMuleMessage.java

private void writeObject(ObjectOutputStream out) throws Exception {
    out.defaultWriteObject();//from  ww w  . ja v a 2s . co m
    if (payload instanceof Serializable) {
        out.writeBoolean(true);
        out.writeObject(payload);
    } else {
        out.writeBoolean(false);
        byte[] serializablePayload = getPayloadAsBytes();
        out.writeInt(serializablePayload.length);
        out.write(serializablePayload);
    }
    out.writeObject(serializeAttachments(inboundAttachments));
    out.writeObject(serializeAttachments(outboundAttachments));

    // TODO: we don't serialize the originalPayload for now
}