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:net.sf.maltcms.chromaui.annotations.XYSelectableShapeAnnotation.java

/**
 * Provides serialization support./*from   w ww .  ja  v a 2 s. c  om*/
 *
 * @param stream the output stream.
 *
 * @throws IOException if there is an I/O error.
 */
private void writeObject(ObjectOutputStream stream) throws IOException {
    stream.defaultWriteObject();
    SerialUtilities.writeShape(this.s, stream);
    SerialUtilities.writeStroke(this.stroke, stream);
    SerialUtilities.writePaint(this.outline, stream);
    SerialUtilities.writePaint(this.highlight, stream);
    stream.writeBoolean(this.active);
}

From source file:idontwant2see.IDontWant2See.java

public void writeData(final ObjectOutputStream out) throws IOException {
    // sort the list so that often used entries are in the front (for faster lookup)
    Collections.sort(mSettings.getSearchList(), new Comparator<IDontWant2SeeListEntry>() {

        public int compare(IDontWant2SeeListEntry o1, IDontWant2SeeListEntry o2) {
            return o2.getLastMatchedDate().compareTo(o1.getLastMatchedDate());
        }//from   w ww.  ja  va  2 s. c o m
    });

    out.writeInt(7); //version
    out.writeInt(mSettings.getSearchList().size());

    for (IDontWant2SeeListEntry entry : mSettings.getSearchList()) {
        entry.writeData(out);
    }

    out.writeBoolean(mSettings.isSimpleMenu());
    out.writeBoolean(mSettings.isSwitchToMyFilter());

    out.writeUTF(mSettings.getLastEnteredExclusionString());

    mSettings.getLastUsedDate().writeData((DataOutput) out);

    out.writeByte(mSettings.getProgramImportance());
}

From source file:com.projity.pm.resource.EnterpriseResource.java

private void writeObject(ObjectOutputStream s) throws IOException {
    s.defaultWriteObject();/*www .  ja v  a  2s  .  com*/
    hasKey.serialize(s);
    costRateTables.serialize(s);
    customFields.serialize(s);
    s.writeInt(hasAssignments.getSchedulingType());
    s.writeBoolean(hasAssignments.isEffortDriven());
    availabilityTable.serialize(s);
}

From source file:org.hibernate.internal.SessionFactoryImpl.java

/**
 * Custom serialization hook used during Session serialization.
 * /*from   ww w  . java  2  s  .  c o m*/
 * @param oos
 *            The stream to which to write the factory
 * @throws IOException
 *             Indicates problems writing out the serial data stream
 */
void serialize(ObjectOutputStream oos) throws IOException {
    oos.writeUTF(uuid);
    oos.writeBoolean(name != null);
    if (name != null) {
        oos.writeUTF(name);
    }
}

From source file:gate.annotation.AnnotationSetImpl.java

private void writeObject(java.io.ObjectOutputStream out) throws IOException {
    ObjectOutputStream.PutField pf = out.putFields();
    pf.put("name", this.name);
    pf.put("doc", this.doc);
    ////from   w w w.j a  v a  2  s  .co  m
    // out.writeObject(this.name);
    // out.writeObject(this.doc);
    // save only the annotations
    // in an array that will prevent the need for casting
    // when deserializing
    annotations = new Annotation[this.annotsById.size()];
    annotations = this.annotsById.values().toArray(annotations);
    // out.writeObject(annotations);
    pf.put("annotations", this.annotations);
    out.writeFields();
    annotations = null;
    boolean isIndexedByType = (this.annotsByType != null);
    boolean isIndexedByStartNode = (this.annotsByStartNode != null);
    out.writeBoolean(isIndexedByType);
    out.writeBoolean(isIndexedByStartNode);
}

From source file:com.sworddance.util.perf.LapTimer.java

private void writeObject(ObjectOutputStream out) throws IOException {
    boolean skipCheck = this.home == null;

    // check to see if this LapTimer was received remotely.
    // if its homeVMID was not set then this JVM/ClassLoader
    // is created it and is sending it out.
    if (skipCheck) {
        synchronized (vmid) {
            this.home = new Id(vmid, remotingCounter++);
        }/*  w  ww .j a v  a 2s  . co  m*/
    }
    if (skipCheck || LapTimer.receivedLaptimers.remove(this.home) == null) {
        LapTimer.sentLaptimers.put(this.home, this);
    }
    boolean restart = this.isRunning();
    if (restart) {
        this.beginNewLap("XMIT");
        //            this.pause(); TODO how to handle staying on same machine?
    }
    out.writeBoolean(restart);
    out.defaultWriteObject();
}

From source file:hudson.FilePath.java

private void writeObject(ObjectOutputStream oos) throws IOException {
    Channel target = Channel.current();

    if (channel != null && channel != target)
        throw new IllegalStateException("Can't send a remote FilePath to a different remote channel");

    oos.defaultWriteObject();//from  w w  w.  j ava 2s .  c om
    oos.writeBoolean(channel == null);
}

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

/**
 * This method is called when there is a timeout and the request has already been forwarded to the leader
 * @param requestList List of requests that the replica wanted to order but didn't manage to
 *//* ww w . j  a  v  a 2 s  .  com*/
public void triggerTimeout(List<TOMMessage> requestList) {

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

    requestsTimer.stopTimer();
    requestsTimer.Enabled(false);

    // still not in the leader change phase?

    if (lcManager.getNextReg() == lcManager.getLastReg()) {

        Logger.println("(TOMLayer.triggerTimeout) initialize synch phase");

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

        int regency = lcManager.getNextReg();

        // store messages to be ordered
        lcManager.setCurrentRequestTimedOut(requestList);

        // store information about messages that I'm going to send
        lcManager.addStop(regency, this.controller.getStaticConf().getProcessId());

        execManager.stop(); // stop consensus execution

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

            if (lcManager.getCurrentRequestTimedOut() != null) {

                //TODO: If this is null, then there was no timeout. What to do?
                byte[] msgs = bb.makeBatch(lcManager.getCurrentRequestTimedOut(), 0, 0, controller);
                out.writeBoolean(true);
                out.writeObject(msgs);
            } else {
                out.writeBoolean(false);
            }

            byte[] payload = bos.toByteArray();

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

            out.close();
            bos.close();

            // send STOP-message
            Logger.println("(TOMLayer.triggerTimeout) sending STOP message to install regency " + regency);
            communication.send(this.controller.getCurrentViewOtherAcceptors(), new LCMessage(
                    this.controller.getStaticConf().getProcessId(), TOMUtil.STOP, regency, payload));

        } 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);
            }
        }

        evaluateStops(regency); // evaluate STOP messages

    }

}

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

private void evaluateStops(int nextReg) {

    boolean enterFirstPhase = this.controller.getStaticConf().isBFT();
    boolean condition = false;
    ObjectOutputStream out = null;
    ByteArrayOutputStream bos = null;

    // pass to the leader change phase if more than f messages have been received already
    if (enterFirstPhase && lcManager.getStopsSize(nextReg) > this.controller.getQuorumF()
            && lcManager.getNextReg() == lcManager.getLastReg()) {

        Logger.println("(TOMLayer.evaluateStops) initialize synch phase");
        requestsTimer.Enabled(false);/*from   ww  w.  j  a  v  a2s .  c o  m*/
        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

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

            if (lcManager.getCurrentRequestTimedOut() != null) {

                //TODO: If this is null, there was no timeout. What shall be done then?
                out.writeBoolean(true);
                byte[] msgs = bb.makeBatch(lcManager.getCurrentRequestTimedOut(), 0, 0, controller);
                out.writeObject(msgs);
            } else {
                out.writeBoolean(false);
            }

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

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

            // send message STOP
            Logger.println("(TOMLayer.evaluateStops) sending STOP message to install regency " + regency);
            communication.send(this.controller.getCurrentViewOtherAcceptors(), new LCMessage(
                    this.controller.getStaticConf().getProcessId(), TOMUtil.STOP, regency, payload));

        } 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) > this.controller.getCertificateQuorum()
                && lcManager.getNextReg() > lcManager.getLastReg();
    } else {
        condition = (lcManager.getStopsSize(nextReg) > this.controller.getQuorumAccept()
                && lcManager.getNextReg() > lcManager.getLastReg());
    }
    // May I proceed to the synchronization phase?
    //if (lcManager.getStopsSize(nextReg) > this.reconfManager.getQuorum2F() && lcManager.getNextReg() > lcManager.getLastReg()) {
    if (condition) {

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

        int regency = lcManager.getLastReg();

        // avoid a memory leak
        lcManager.removeStops(nextReg);

        requestsTimer.Enabled(true);
        requestsTimer.setShortTimeout(-1);
        //requestsTimer.setTimeout(requestsTimer.getTimeout() * 2);
        requestsTimer.startTimer();

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

        lm.setNewLeader(leader);

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

            try { // serialize content of the SYNC message

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

                if (last > -1) { // content of the last decided eid

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

                    ////// ISTO E PARA APANHAR UM BUG!!!!!
                    if (exec.getDecisionRound() == null || exec.getDecisionRound().propValue == null) {

                        System.out.println("[DEBUG INFO FOR LAST EID #1]");

                        if (exec.getDecisionRound() == null) {
                            System.out.println("No decision round for eid " + last);
                        } else {
                            System.out.println(
                                    "round for eid: " + last + ": " + exec.getDecisionRound().toString());

                            if (exec.getDecisionRound().propValue == null)
                                System.out.println("No propose for eid " + last);
                            else {
                                System.out.println("Propose hash for eid " + last + ": " + Base64
                                        .encodeBase64String(computeHash(exec.getDecisionRound().propValue)));
                            }
                        }

                        return;
                    }

                    byte[] decision = exec.getDecisionRound().propValue;
                    Set<PaxosMessage> proof = exec.getDecisionRound().getProof();

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

                }

                else
                    out.writeBoolean(false);

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

                    Execution exec = execManager.getExecution(in);

                    TimestampValuePair quorumWrites = exec.getQuorumWrites();
                    HashSet<TimestampValuePair> writeSet = exec.getWriteSet();

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

                    SignedObject signedCollect = sign(collect);

                    out.writeObject(signedCollect);

                }

                else {

                    CollectData collect = new CollectData(this.controller.getStaticConf().getProcessId(), -1,
                            new TimestampValuePair(-1, new byte[0]), new HashSet<TimestampValuePair>());

                    SignedObject signedCollect = 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;

                Logger.println("(TOMLayer.evaluateStops) 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);
                }
            }

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

            Logger.println("(TOMLayer.evaluateStops) I'm the leader for this new regency");
            LastEidData lastData = null;
            CollectData collect = null;

            if (last > -1) { // content of the last decided eid 
                Execution exec = execManager.getExecution(last);
                //byte[] decision = exec.getLearner().getDecision();

                ////// ISTO E PARA APANHAR UM BUG!!!!!
                if (exec.getDecisionRound() == null || exec.getDecisionRound().propValue == null) {

                    System.out.println("[DEBUG INFO FOR LAST EID #2]");

                    if (exec.getDecisionRound() == null)
                        System.out.println("No decision round for eid " + last);
                    else
                        System.out
                                .println("round for eid: " + last + ": " + exec.getDecisionRound().toString());
                    if (exec.getDecisionRound().propValue == null)
                        System.out.println("No propose for eid " + last);
                    else {
                        System.out.println("Propose hash for eid " + last + ": "
                                + Base64.encodeBase64String(computeHash(exec.getDecisionRound().propValue)));
                    }

                    return;
                }

                byte[] decision = exec.getDecisionRound().propValue;
                Set<PaxosMessage> proof = exec.getDecisionRound().getProof();

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

            } else {
                lastData = new LastEidData(this.controller.getStaticConf().getProcessId(), last, null, null);
            }
            lcManager.addLastEid(regency, lastData);

            if (in > -1) { // content of eid being executed
                Execution exec = execManager.getExecution(in);

                TimestampValuePair quorumWrites = exec.getQuorumWrites();
                HashSet<TimestampValuePair> writeSet = exec.getWriteSet();

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

            } else {
                collect = new CollectData(this.controller.getStaticConf().getProcessId(), -1,
                        new TimestampValuePair(-1, new byte[0]), new HashSet<TimestampValuePair>());
            }

            SignedObject signedCollect = sign(collect);

            lcManager.addCollect(regency, signedCollect);
        }

    }
}

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

/**
 * This method is called when there is a timeout and the request has already
 * been forwarded to the leader/*  w  w  w . j  a v  a 2  s  . c o m*/
 *
 * @param requestList List of requests that the replica wanted to order but
 * didn't manage to
 */
public void triggerTimeout(List<TOMMessage> requestList) {

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

    int regency = lcManager.getNextReg();

    requestsTimer.stopTimer();
    requestsTimer.Enabled(false);

    // still not in the leader change phase?
    if (lcManager.getNextReg() == lcManager.getLastReg()) {

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

        regency = lcManager.getNextReg(); // update variable 

        // store messages to be ordered
        lcManager.setCurrentRequestTimedOut(requestList);

        // store information about messages that I'm going to send
        lcManager.addStop(regency, this.controller.getStaticConf().getProcessId());

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

        //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 content to send in STOP message
            out = new ObjectOutputStream(bos);

            if (messages != null && messages.size() > 0) {

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

            byte[] payload = bos.toByteArray();

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

            out.close();
            bos.close();

            // send STOP-message                
            System.out.println("(Synchronizer.triggerTimeout) 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);
            }
        }

    }

    processOutOfContextSTOPs(regency); // the replica might have received STOPs
                                       // that were out of context at the time they
                                       // were received, but now can be processed

    startSynchronization(regency); // evaluate STOP messages

}