Java 类org.apache.zookeeper.ZooDefs.OpCode 实例源码

项目:fuck_zookeeper    文件:SendAckRequestProcessor.java   
public void processRequest(Request si) {
    if(si.type != OpCode.sync){
        QuorumPacket qp = new QuorumPacket(Leader.ACK, si.hdr.getZxid(), null,
            null);
        try {
            learner.writePacket(qp, false);
        } catch (IOException e) {
            LOG.warn("Closing connection to leader, exception during packet send", e);
            try {
                if (!learner.sock.isClosed()) {
                    learner.sock.close();
                }
            } catch (IOException e1) {
                // Nothing to do, we are shutting things down, so an exception here is irrelevant
                LOG.debug("Ignoring error closing the connection", e1);
            }
        }
    }
}
项目:fuck_zookeeper    文件:Request.java   
static boolean isQuorum(int type) {
    switch (type) {
    case OpCode.exists:
    case OpCode.getACL:
    case OpCode.getChildren:
    case OpCode.getChildren2:
    case OpCode.getData:
        return false;
    case OpCode.error:
    case OpCode.closeSession:
    case OpCode.create:
    case OpCode.createSession:
    case OpCode.delete:
    case OpCode.setACL:
    case OpCode.setData:
    case OpCode.check:
    case OpCode.multi:
        return true;
    default:
        return false;
    }
}
项目:fuck_zookeeper    文件:ZooKeeperServer.java   
public ProcessTxnResult processTxn(TxnHeader hdr, Record txn) {
    ProcessTxnResult rc;
    int opCode = hdr.getType();
    long sessionId = hdr.getClientId();
    rc = getZKDatabase().processTxn(hdr, txn);
    if (opCode == OpCode.createSession) {
        if (txn instanceof CreateSessionTxn) {
            CreateSessionTxn cst = (CreateSessionTxn) txn;
            sessionTracker.addSession(sessionId, cst
                    .getTimeOut());
        } else {
            LOG.warn("*****>>>>> Got "
                    + txn.getClass() + " "
                    + txn.toString());
        }
    } else if (opCode == OpCode.closeSession) {
        sessionTracker.removeSession(sessionId);
    }
    return rc;
}
项目:fuck_zookeeper    文件:ClientCnxn.java   
/**
 * Close the connection, which includes; send session disconnect to the
 * server, shutdown the send/event threads.
 *
 * @throws IOException
 */
public void close() throws IOException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Closing client for session: 0x"
                  + Long.toHexString(getSessionId()));
    }

    try {
        RequestHeader h = new RequestHeader();
        h.setType(ZooDefs.OpCode.closeSession);

        submitRequest(h, null, null, null);
    } catch (InterruptedException e) {
        // ignore, close the send/event threads
    } finally {
        disconnect();
    }
}
项目:fuck_zookeeper    文件:LoadFromLogTest.java   
/**
 * Simulates ZOOKEEPER-1069 and verifies that flush() before padLogFile
 * fixes it.
 */
@Test
public void testPad() throws Exception {
    File tmpDir = ClientBase.createTmpDir();
    FileTxnLog txnLog = new FileTxnLog(tmpDir);
    TxnHeader txnHeader = new TxnHeader(0xabcd, 0x123, 0x123,
          System.currentTimeMillis(), OpCode.create);
    Record txn = new CreateTxn("/Test", new byte[0], null, false, 1);
    txnLog.append(txnHeader, txn);
    FileInputStream in = new FileInputStream(tmpDir.getPath() + "/log." +
          Long.toHexString(txnHeader.getZxid()));
    BinaryInputArchive ia  = BinaryInputArchive.getArchive(in);
    FileHeader header = new FileHeader();
    header.deserialize(ia, "fileheader");
    LOG.info("Received magic : " + header.getMagic() +
          " Expected : " + FileTxnLog.TXNLOG_MAGIC);
    Assert.assertTrue("Missing magic number ",
          header.getMagic() == FileTxnLog.TXNLOG_MAGIC);
}
项目:https-github.com-apache-zookeeper    文件:FollowerRequestProcessor.java   
public void processRequest(Request request) {
    if (!finished) {
        // Before sending the request, check if the request requires a
        // global session and what we have is a local session. If so do
        // an upgrade.
        Request upgradeRequest = null;
        try {
            upgradeRequest = zks.checkUpgradeSession(request);
        } catch (KeeperException ke) {
            if (request.getHdr() != null) {
                request.getHdr().setType(OpCode.error);
                request.setTxn(new ErrorTxn(ke.code().intValue()));
            }
            request.setException(ke);
            LOG.info("Error creating upgrade request",  ke);
        } catch (IOException ie) {
            LOG.error("Unexpected error in upgrade", ie);
        }
        if (upgradeRequest != null) {
            queuedRequests.add(upgradeRequest);
        }
        queuedRequests.add(request);
    }
}
项目:https-github.com-apache-zookeeper    文件:ObserverRequestProcessor.java   
/**
 * Simply queue the request, which will be processed in FIFO order.
 */
public void processRequest(Request request) {
    if (!finished) {
        Request upgradeRequest = null;
        try {
            upgradeRequest = zks.checkUpgradeSession(request);
        } catch (KeeperException ke) {
            if (request.getHdr() != null) {
                request.getHdr().setType(OpCode.error);
                request.setTxn(new ErrorTxn(ke.code().intValue()));
            }
            request.setException(ke);
            LOG.info("Error creating upgrade request",  ke);
        } catch (IOException ie) {
            LOG.error("Unexpected error in upgrade", ie);
        }
        if (upgradeRequest != null) {
            queuedRequests.add(upgradeRequest);
        }
        queuedRequests.add(request);
    }
}
项目:https-github.com-apache-zookeeper    文件:SendAckRequestProcessor.java   
public void processRequest(Request si) {
    if(si.type != OpCode.sync){
        QuorumPacket qp = new QuorumPacket(Leader.ACK, si.getHdr().getZxid(), null,
            null);
        try {
            learner.writePacket(qp, false);
        } catch (IOException e) {
            LOG.warn("Closing connection to leader, exception during packet send", e);
            try {
                if (!learner.sock.isClosed()) {
                    learner.sock.close();
                }
            } catch (IOException e1) {
                // Nothing to do, we are shutting things down, so an exception here is irrelevant
                LOG.debug("Ignoring error closing the connection", e1);
            }
        }
    }
}
项目:https-github.com-apache-zookeeper    文件:CommitProcessor.java   
protected boolean needCommit(Request request) {
    switch (request.type) {
        case OpCode.create:
        case OpCode.create2:
        case OpCode.createTTL:
        case OpCode.createContainer:
        case OpCode.delete:
        case OpCode.deleteContainer:
        case OpCode.setData:
        case OpCode.reconfig:
        case OpCode.multi:
        case OpCode.setACL:
            return true;
        case OpCode.sync:
            return matchSyncs;    
        case OpCode.createSession:
        case OpCode.closeSession:
            return !request.isLocalSession();
        default:
            return false;
    }
}
项目:https-github.com-apache-zookeeper    文件:LeaderRequestProcessor.java   
@Override
public void processRequest(Request request)
        throws RequestProcessorException {
    // Check if this is a local session and we are trying to create
    // an ephemeral node, in which case we upgrade the session
    Request upgradeRequest = null;
    try {
        upgradeRequest = lzks.checkUpgradeSession(request);
    } catch (KeeperException ke) {
        if (request.getHdr() != null) {
            LOG.debug("Updating header");
            request.getHdr().setType(OpCode.error);
            request.setTxn(new ErrorTxn(ke.code().intValue()));
        }
        request.setException(ke);
        LOG.info("Error creating upgrade request " + ke.getMessage());
    } catch (IOException ie) {
        LOG.error("Unexpected error in upgrade", ie);
    }
    if (upgradeRequest != null) {
        nextProcessor.processRequest(upgradeRequest);
    }

    nextProcessor.processRequest(request);
}
项目:https-github.com-apache-zookeeper    文件:QuorumZooKeeperServer.java   
@Override
protected void setLocalSessionFlag(Request si) {
    // We need to set isLocalSession to tree for these type of request
    // so that the request processor can process them correctly.
    switch (si.type) {
    case OpCode.createSession:
        if (self.areLocalSessionsEnabled()) {
            // All new sessions local by default.
            si.setLocalSession(true);
        }
        break;
    case OpCode.closeSession:
        String reqType = "global";
        if (upgradeableSessionTracker.isLocalSession(si.sessionId)) {
            si.setLocalSession(true);
            reqType = "local";
        }
        LOG.info("Submitting " + reqType + " closeSession request"
                + " for session 0x" + Long.toHexString(si.sessionId));
        break;
    default:
        break;
    }
}
项目:https-github.com-apache-zookeeper    文件:ZooKeeperServer.java   
long createSession(ServerCnxn cnxn, byte passwd[], int timeout) {
    if (passwd == null) {
        // Possible since it's just deserialized from a packet on the wire.
        passwd = new byte[0];
    }
    long sessionId = sessionTracker.createSession(timeout);
    Random r = new Random(sessionId ^ superSecret);
    r.nextBytes(passwd);
    ByteBuffer to = ByteBuffer.allocate(4);
    to.putInt(timeout);
    cnxn.setSessionId(sessionId);
    Request si = new Request(cnxn, sessionId, 0, OpCode.createSession, to, null);
    setLocalSessionFlag(si);
    submitRequest(si);
    return sessionId;
}
项目:https-github.com-apache-zookeeper    文件:ClientCnxn.java   
/**
 * Close the connection, which includes; send session disconnect to the
 * server, shutdown the send/event threads.
 *
 * @throws IOException
 */
public void close() throws IOException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Closing client for session: 0x"
                  + Long.toHexString(getSessionId()));
    }

    try {
        RequestHeader h = new RequestHeader();
        h.setType(ZooDefs.OpCode.closeSession);

        submitRequest(h, null, null, null);
    } catch (InterruptedException e) {
        // ignore, close the send/event threads
    } finally {
        disconnect();
    }
}
项目:https-github.com-apache-zookeeper    文件:CommitProcessorConcurrencyTest.java   
/**
 * In the following test, we verify that committed requests are processed
 * even when queuedRequests never gets empty. We add 10 committed request
 * and use infinite queuedRequests. We verify that the committed request was
 * processed.
 */
@Test(timeout = 1000)
public void noStarvationOfNonLocalCommittedRequestsTest() throws Exception {
    final String path = "/noStarvationOfCommittedRequests";
    processor.queuedRequests = new MockRequestsQueue();
    Set<Request> nonLocalCommits = new HashSet<Request>();
    for (int i = 0; i < 10; i++) {
        Request nonLocalCommitReq = newRequest(
                new CreateRequest(path, new byte[0], Ids.OPEN_ACL_UNSAFE,
                        CreateMode.PERSISTENT_SEQUENTIAL.toFlag()),
                OpCode.create, 51, i + 1);
        processor.committedRequests.add(nonLocalCommitReq);
        nonLocalCommits.add(nonLocalCommitReq);
    }
    for (int i = 0; i < 10; i++) {
        processor.initThreads(defaultSizeOfThreadPool);
        processor.stoppedMainLoop = true;
        processor.run();
    }
    Assert.assertTrue("commit request was not processed",
            processedRequests.containsAll(nonLocalCommits));
}
项目:https-github.com-apache-zookeeper    文件:LoadFromLogTest.java   
/**
 * Simulates ZOOKEEPER-1069 and verifies that flush() before padLogFile
 * fixes it.
 */
@Test
public void testPad() throws Exception {
    File tmpDir = ClientBase.createTmpDir();
    FileTxnLog txnLog = new FileTxnLog(tmpDir);
    TxnHeader txnHeader = new TxnHeader(0xabcd, 0x123, 0x123,
          Time.currentElapsedTime(), OpCode.create);
    Record txn = new CreateTxn("/Test", new byte[0], null, false, 1);
    txnLog.append(txnHeader, txn);
    FileInputStream in = new FileInputStream(tmpDir.getPath() + "/log." +
          Long.toHexString(txnHeader.getZxid()));
    BinaryInputArchive ia  = BinaryInputArchive.getArchive(in);
    FileHeader header = new FileHeader();
    header.deserialize(ia, "fileheader");
    LOG.info("Received magic : " + header.getMagic() +
          " Expected : " + FileTxnLog.TXNLOG_MAGIC);
    Assert.assertTrue("Missing magic number ",
          header.getMagic() == FileTxnLog.TXNLOG_MAGIC);
}
项目:ZooKeeper    文件:SendAckRequestProcessor.java   
public void processRequest(Request si) {
    if(si.type != OpCode.sync){
        QuorumPacket qp = new QuorumPacket(Leader.ACK, si.hdr.getZxid(), null,
            null);
        try {
            learner.writePacket(qp, false);
        } catch (IOException e) {
            LOG.warn("Closing connection to leader, exception during packet send", e);
            try {
                if (!learner.sock.isClosed()) {
                    learner.sock.close();
                }
            } catch (IOException e1) {
                // Nothing to do, we are shutting things down, so an exception here is irrelevant
                LOG.debug("Ignoring error closing the connection", e1);
            }
        }
    }
}
项目:ZooKeeper    文件:Request.java   
static boolean isQuorum(int type) {
    switch (type) {
    case OpCode.exists:
    case OpCode.getACL:
    case OpCode.getChildren:
    case OpCode.getChildren2:
    case OpCode.getData:
        return false;
    case OpCode.error:
    case OpCode.closeSession:
    case OpCode.create:
    case OpCode.createSession:
    case OpCode.delete:
    case OpCode.setACL:
    case OpCode.setData:
    case OpCode.check:
    case OpCode.multi:
        return true;
    default:
        return false;
    }
}
项目:ZooKeeper    文件:ZooKeeperServer.java   
public ProcessTxnResult processTxn(TxnHeader hdr, Record txn) {
    ProcessTxnResult rc;
    int opCode = hdr.getType();
    long sessionId = hdr.getClientId();
    rc = getZKDatabase().processTxn(hdr, txn);
    if (opCode == OpCode.createSession) {
        if (txn instanceof CreateSessionTxn) {
            CreateSessionTxn cst = (CreateSessionTxn) txn;
            sessionTracker.addSession(sessionId, cst
                    .getTimeOut());
        } else {
            LOG.warn("*****>>>>> Got "
                    + txn.getClass() + " "
                    + txn.toString());
        }
    } else if (opCode == OpCode.closeSession) {
        sessionTracker.removeSession(sessionId);
    }
    return rc;
}
项目:ZooKeeper    文件:ClientCnxn.java   
/**
 * Close the connection, which includes; send session disconnect to the
 * server, shutdown the send/event threads.
 *
 * @throws IOException
 */
public void close() throws IOException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Closing client for session: 0x"
                  + Long.toHexString(getSessionId()));
    }

    try {
        RequestHeader h = new RequestHeader();
        h.setType(ZooDefs.OpCode.closeSession);

        submitRequest(h, null, null, null);
    } catch (InterruptedException e) {
        // ignore, close the send/event threads
    } finally {
        disconnect();
    }
}
项目:ZooKeeper    文件:LoadFromLogTest.java   
/**
 * Simulates ZOOKEEPER-1069 and verifies that flush() before padLogFile
 * fixes it.
 */
@Test
public void testPad() throws Exception {
    File tmpDir = ClientBase.createTmpDir();
    FileTxnLog txnLog = new FileTxnLog(tmpDir);
    TxnHeader txnHeader = new TxnHeader(0xabcd, 0x123, 0x123,
          System.currentTimeMillis(), OpCode.create);
    Record txn = new CreateTxn("/Test", new byte[0], null, false, 1);
    txnLog.append(txnHeader, txn);
    FileInputStream in = new FileInputStream(tmpDir.getPath() + "/log." +
          Long.toHexString(txnHeader.getZxid()));
    BinaryInputArchive ia  = BinaryInputArchive.getArchive(in);
    FileHeader header = new FileHeader();
    header.deserialize(ia, "fileheader");
    LOG.info("Received magic : " + header.getMagic() +
          " Expected : " + FileTxnLog.TXNLOG_MAGIC);
    Assert.assertTrue("Missing magic number ",
          header.getMagic() == FileTxnLog.TXNLOG_MAGIC);
}
项目:zookeeper    文件:Request.java   
static boolean isQuorum(int type) {
    switch (type) {
    case OpCode.exists:
    case OpCode.getACL:
    case OpCode.getChildren:
    case OpCode.getChildren2:
    case OpCode.getData:
        return false;
    case OpCode.error:
    case OpCode.closeSession:
    case OpCode.create:
    case OpCode.createSession:
    case OpCode.delete:
    case OpCode.setACL:
    case OpCode.setData:
    case OpCode.check:
    case OpCode.multi:
        return true;
    default:
        return false;
    }
}
项目:StreamProcessingInfrastructure    文件:ClientCnxn.java   
/**
 * Close the connection, which includes; send session disconnect to the
 * server, shutdown the send/event threads.
 *
 * @throws IOException
 */
public void close() throws IOException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Closing client for session: 0x"
                  + Long.toHexString(getSessionId()));
    }

    try {
        RequestHeader h = new RequestHeader();
        h.setType(ZooDefs.OpCode.closeSession);

        submitRequest(h, null, null, null);
    } catch (InterruptedException e) {
        // ignore, close the send/event threads
    } finally {
        disconnect();
    }
}
项目:StreamProcessingInfrastructure    文件:LoadFromLogTest.java   
/**
 * Simulates ZOOKEEPER-1069 and verifies that flush() before padLogFile
 * fixes it.
 */
@Test
public void testPad() throws Exception {
    File tmpDir = ClientBase.createTmpDir();
    FileTxnLog txnLog = new FileTxnLog(tmpDir);
    TxnHeader txnHeader = new TxnHeader(0xabcd, 0x123, 0x123,
          System.currentTimeMillis(), OpCode.create);
    Record txn = new CreateTxn("/Test", new byte[0], null, false, 1);
    txnLog.append(txnHeader, txn);
    FileInputStream in = new FileInputStream(tmpDir.getPath() + "/log." +
          Long.toHexString(txnHeader.getZxid()));
    BinaryInputArchive ia  = BinaryInputArchive.getArchive(in);
    FileHeader header = new FileHeader();
    header.deserialize(ia, "fileheader");
    LOG.info("Received magic : " + header.getMagic() +
          " Expected : " + FileTxnLog.TXNLOG_MAGIC);
    Assert.assertTrue("Missing magic number ",
          header.getMagic() == FileTxnLog.TXNLOG_MAGIC);
}
项目:SecureKeeper    文件:ObserverRequestProcessor.java   
/**
 * Simply queue the request, which will be processed in FIFO order.
 */
public void processRequest(Request request) {
    if (!finished) {
        Request upgradeRequest = null;
        try {
            upgradeRequest = zks.checkUpgradeSession(request);
        } catch (KeeperException ke) {
            if (request.getHdr() != null) {
                request.getHdr().setType(OpCode.error);
                request.setTxn(new ErrorTxn(ke.code().intValue()));
            }
            request.setException(ke);
            LOG.info("Error creating upgrade request",  ke);
        } catch (IOException ie) {
            LOG.error("Unexpected error in upgrade", ie);
        }
        if (upgradeRequest != null) {
            queuedRequests.add(upgradeRequest);
        }
        queuedRequests.add(request);
    }
}
项目:SecureKeeper    文件:FollowerRequestProcessor.java   
public void processRequest(Request request) {
    if (!finished) {
        // Before sending the request, check if the request requires a
        // global session and what we have is a local session. If so do
        // an upgrade.
        Request upgradeRequest = null;
        try {
            upgradeRequest = zks.checkUpgradeSession(request);
        } catch (KeeperException ke) {
            if (request.getHdr() != null) {
                request.getHdr().setType(OpCode.error);
                request.setTxn(new ErrorTxn(ke.code().intValue()));
            }
            request.setException(ke);
            LOG.info("Error creating upgrade request",  ke);
        } catch (IOException ie) {
            LOG.error("Unexpected error in upgrade", ie);
        }
        if (upgradeRequest != null) {
            queuedRequests.add(upgradeRequest);
        }
        queuedRequests.add(request);
    }
}
项目:bigstreams    文件:SendAckRequestProcessor.java   
public void processRequest(Request si) {
    if(si.type != OpCode.sync){
        QuorumPacket qp = new QuorumPacket(Leader.ACK, si.hdr.getZxid(), null,
            null);
        try {
            learner.writePacket(qp, false);
        } catch (IOException e) {
            LOG.warn("Closing connection to leader, exception during packet send", e);
            try {
                if (!learner.sock.isClosed()) {
                    learner.sock.close();
                }
            } catch (IOException e1) {
                // Nothing to do, we are shutting things down, so an exception here is irrelevant
                LOG.debug("Ignoring error closing the connection", e1);
            }
        }
    }
}
项目:bigstreams    文件:Request.java   
static boolean isQuorum(int type) {
    switch (type) {
    case OpCode.exists:
    case OpCode.getACL:
    case OpCode.getChildren:
    case OpCode.getChildren2:
    case OpCode.getData:
        return false;
    case OpCode.error:
    case OpCode.closeSession:
    case OpCode.create:
    case OpCode.createSession:
    case OpCode.delete:
    case OpCode.setACL:
    case OpCode.setData:
    case OpCode.check:
    case OpCode.multi:
        return true;
    default:
        return false;
    }
}
项目:bigstreams    文件:ZooKeeperServer.java   
public ProcessTxnResult processTxn(TxnHeader hdr, Record txn) {
    ProcessTxnResult rc;
    int opCode = hdr.getType();
    long sessionId = hdr.getClientId();
    rc = getZKDatabase().processTxn(hdr, txn);
    if (opCode == OpCode.createSession) {
        if (txn instanceof CreateSessionTxn) {
            CreateSessionTxn cst = (CreateSessionTxn) txn;
            sessionTracker.addSession(sessionId, cst
                    .getTimeOut());
        } else {
            LOG.warn("*****>>>>> Got "
                    + txn.getClass() + " "
                    + txn.toString());
        }
    } else if (opCode == OpCode.closeSession) {
        sessionTracker.removeSession(sessionId);
    }
    return rc;
}
项目:zookeeper    文件:LoadFromLogTest.java   
/**
 * Simulates ZOOKEEPER-1069 and verifies that flush() before padLogFile
 * fixes it.
 */
@Test
public void testPad() throws Exception {
    File tmpDir = ClientBase.createTmpDir();
    FileTxnLog txnLog = new FileTxnLog(tmpDir);
    TxnHeader txnHeader = new TxnHeader(0xabcd, 0x123, 0x123,
          System.currentTimeMillis(), OpCode.create);
    Record txn = new CreateTxn("/Test", new byte[0], null, false, 1);
    txnLog.append(txnHeader, txn);
    FileInputStream in = new FileInputStream(tmpDir.getPath() + "/log." +
          Long.toHexString(txnHeader.getZxid()));
    BinaryInputArchive ia  = BinaryInputArchive.getArchive(in);
    FileHeader header = new FileHeader();
    header.deserialize(ia, "fileheader");
    LOG.info("Received magic : " + header.getMagic() +
          " Expected : " + FileTxnLog.TXNLOG_MAGIC);
    Assert.assertTrue("Missing magic number ",
          header.getMagic() == FileTxnLog.TXNLOG_MAGIC);
}
项目:SecureKeeper    文件:ObserverRequestProcessor.java   
/**
 * Simply queue the request, which will be processed in FIFO order.
 */
public void processRequest(Request request) {
    if (!finished) {
        Request upgradeRequest = null;
        try {
            upgradeRequest = zks.checkUpgradeSession(request);
        } catch (KeeperException ke) {
            if (request.getHdr() != null) {
                request.getHdr().setType(OpCode.error);
                request.setTxn(new ErrorTxn(ke.code().intValue()));
            }
            request.setException(ke);
            LOG.info("Error creating upgrade request",  ke);
        } catch (IOException ie) {
            LOG.error("Unexpected error in upgrade", ie);
        }
        if (upgradeRequest != null) {
            queuedRequests.add(upgradeRequest);
        }
        queuedRequests.add(request);
    }
}
项目:bigstreams    文件:LoadFromLogTest.java   
/**
 * Simulates ZOOKEEPER-1069 and verifies that flush() before padLogFile
 * fixes it.
 */
@Test
public void testPad() throws Exception {
    File tmpDir = ClientBase.createTmpDir();
    FileTxnLog txnLog = new FileTxnLog(tmpDir);
    TxnHeader txnHeader = new TxnHeader(0xabcd, 0x123, 0x123,
          System.currentTimeMillis(), OpCode.create);
    Record txn = new CreateTxn("/Test", new byte[0], null, false, 1);
    txnLog.append(txnHeader, txn);
    FileInputStream in = new FileInputStream(tmpDir.getPath() + "/log." +
          Long.toHexString(txnHeader.getZxid()));
    BinaryInputArchive ia  = BinaryInputArchive.getArchive(in);
    FileHeader header = new FileHeader();
    header.deserialize(ia, "fileheader");
    LOG.info("Received magic : " + header.getMagic() +
          " Expected : " + FileTxnLog.TXNLOG_MAGIC);
    Assert.assertTrue("Missing magic number ",
          header.getMagic() == FileTxnLog.TXNLOG_MAGIC);
}
项目:SecureKeeper    文件:SendAckRequestProcessor.java   
public void processRequest(Request si) {
    if(si.type != OpCode.sync){
        QuorumPacket qp = new QuorumPacket(Leader.ACK, si.getHdr().getZxid(), null,
            null);
        try {
            learner.writePacket(qp, false);
        } catch (IOException e) {
            LOG.warn("Closing connection to leader, exception during packet send", e);
            try {
                if (!learner.sock.isClosed()) {
                    learner.sock.close();
                }
            } catch (IOException e1) {
                // Nothing to do, we are shutting things down, so an exception here is irrelevant
                LOG.debug("Ignoring error closing the connection", e1);
            }
        }
    }
}
项目:SecureKeeper    文件:LeaderRequestProcessor.java   
@Override
public void processRequest(Request request)
        throws RequestProcessorException {
    // Check if this is a local session and we are trying to create
    // an ephemeral node, in which case we upgrade the session
    Request upgradeRequest = null;
    try {
        upgradeRequest = lzks.checkUpgradeSession(request);
    } catch (KeeperException ke) {
        if (request.getHdr() != null) {
            LOG.debug("Updating header");
            request.getHdr().setType(OpCode.error);
            request.setTxn(new ErrorTxn(ke.code().intValue()));
        }
        request.setException(ke);
        LOG.info("Error creating upgrade request " + ke.getMessage());
    } catch (IOException ie) {
        LOG.error("Unexpected error in upgrade", ie);
    }
    if (upgradeRequest != null) {
        nextProcessor.processRequest(upgradeRequest);
    }

    nextProcessor.processRequest(request);
}
项目:bigstreams    文件:Request.java   
static boolean isQuorum(int type) {
    switch (type) {
    case OpCode.exists:
    case OpCode.getACL:
    case OpCode.getChildren:
    case OpCode.getChildren2:
    case OpCode.getData:
        return false;
    case OpCode.error:
    case OpCode.closeSession:
    case OpCode.create:
    case OpCode.createSession:
    case OpCode.delete:
    case OpCode.setACL:
    case OpCode.setData:
        return true;
    default:
        return false;
    }
}
项目:bigstreams    文件:ClientCnxn.java   
/**
 * Close the connection, which includes; send session disconnect to the
 * server, shutdown the send/event threads.
 *
 * @throws IOException
 */
public void close() throws IOException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Closing client for session: 0x"
                  + Long.toHexString(getSessionId()));
    }

    try {
        RequestHeader h = new RequestHeader();
        h.setType(ZooDefs.OpCode.closeSession);

        submitRequest(h, null, null, null);
    } catch (InterruptedException e) {
        // ignore, close the send/event threads
    } finally {
        disconnect();
    }
}
项目:bigstreams    文件:LoadFromLogTest.java   
/**
 * Simulates ZOOKEEPER-1069 and verifies that flush() before padLogFile
 * fixes it.
 */
@Test
public void testPad() throws Exception {
    File tmpDir = ClientBase.createTmpDir();
    FileTxnLog txnLog = new FileTxnLog(tmpDir);
    TxnHeader txnHeader = new TxnHeader(0xabcd, 0x123, 0x123,
          System.currentTimeMillis(), OpCode.create);
    Record txn = new CreateTxn("/Test", new byte[0], null, false, 1);
    txnLog.append(txnHeader, txn);
    FileInputStream in = new FileInputStream(tmpDir.getPath() + "/log." +
          Long.toHexString(txnHeader.getZxid()));
    BinaryInputArchive ia  = BinaryInputArchive.getArchive(in);
    FileHeader header = new FileHeader();
    header.deserialize(ia, "fileheader");
    LOG.info("Expected header :" + header.getMagic() +
          " Received : " + FileTxnLog.TXNLOG_MAGIC);
    Assert.assertTrue("Missing magic number ",
          header.getMagic() == FileTxnLog.TXNLOG_MAGIC);
}
项目:SecureKeeper    文件:ClientCnxn.java   
/**
 * Close the connection, which includes; send session disconnect to the
 * server, shutdown the send/event threads.
 *
 * @throws IOException
 */
public void close() throws IOException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Closing client for session: 0x"
                  + Long.toHexString(getSessionId()));
    }

    try {
        RequestHeader h = new RequestHeader();
        h.setType(ZooDefs.OpCode.closeSession);

        submitRequest(h, null, null, null);
    } catch (InterruptedException e) {
        // ignore, close the send/event threads
    } finally {
        disconnect();
    }
}
项目:SecureKeeper    文件:CommitProcessor.java   
protected boolean needCommit(Request request) {
    switch (request.type) {
        case OpCode.create:
        case OpCode.create2:
        case OpCode.createContainer:
        case OpCode.delete:
        case OpCode.deleteContainer:
        case OpCode.setData:
        case OpCode.reconfig:
        case OpCode.multi:
        case OpCode.setACL:
            return true;
        case OpCode.sync:
            return matchSyncs;    
        case OpCode.createSession:
        case OpCode.closeSession:
            return !request.isLocalSession();
        default:
            return false;
    }
}
项目:SecureKeeper    文件:LoadFromLogTest.java   
/**
 * Simulates ZOOKEEPER-1069 and verifies that flush() before padLogFile
 * fixes it.
 */
@Test
public void testPad() throws Exception {
    File tmpDir = ClientBase.createTmpDir();
    FileTxnLog txnLog = new FileTxnLog(tmpDir);
    TxnHeader txnHeader = new TxnHeader(0xabcd, 0x123, 0x123,
          Time.currentElapsedTime(), OpCode.create);
    Record txn = new CreateTxn("/Test", new byte[0], null, false, 1);
    txnLog.append(txnHeader, txn);
    FileInputStream in = new FileInputStream(tmpDir.getPath() + "/log." +
          Long.toHexString(txnHeader.getZxid()));
    BinaryInputArchive ia  = BinaryInputArchive.getArchive(in);
    FileHeader header = new FileHeader();
    header.deserialize(ia, "fileheader");
    LOG.info("Received magic : " + header.getMagic() +
          " Expected : " + FileTxnLog.TXNLOG_MAGIC);
    Assert.assertTrue("Missing magic number ",
          header.getMagic() == FileTxnLog.TXNLOG_MAGIC);
}
项目:zookeeper-src-learning    文件:ClientCnxn.java   
/**
 * Close the connection, which includes; send session disconnect to the
 * server, shutdown the send/event threads.
 *
 * @throws IOException
 */
public void close() throws IOException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("Closing client for session: 0x"
                + Long.toHexString(getSessionId()));
    }

    try {
        RequestHeader h = new RequestHeader();
        h.setType(ZooDefs.OpCode.closeSession);

        submitRequest(h, null, null, null);
    } catch (InterruptedException e) {
        // ignore, close the send/event threads
    } finally {
        disconnect();
    }
}