public synchronized TransactorNode getTransactorNode() { checkIfClosed(); if (tnode == null) { tnode = new TransactorNode(env, getTransactorID()); } else if (tnode.getStatus() == TrStatus.CLOSED) { throw new IllegalStateException("TransactorNode is closed!"); } return tnode; }
public boolean checkExists(Long transactorId) { return cache.getCurrentData(TransactorNode.getNodePath(env, transactorId)) != null; }
/** * Returns the transactorID of this node */ public TransactorID getTransactorID() { if (getStatus() == TrStatus.CLOSED) { throw new IllegalStateException("TransactorID is closed!"); } return tid; }
/** * Retrieves transactor ID by first getting/creating transactor (which is only done until * necessary) */ private Long getTransactorID() { if (tnode == null) { tnode = env.getSharedResources().getTransactorNode(); } return tnode.getTransactorID().getLongID(); }
@Override public synchronized void close() { isClosed = true; if (tnode != null) { tnode.close(); } if (tsTracker != null) { tsTracker.close(); } if (transactorCache != null) { transactorCache.close(); } if (oracleClient != null) { oracleClient.close(); } cw.close(); bulkCw.close(); sbw.close(); try { bw.close(); } catch (MutationsRejectedException e) { throw new RuntimeException(e); } curator.close(); }
@VisibleForTesting public String getNodePath() { return getNodePath(env, tid.getLongID()); }
/** * Creates a transactor node using given transactor id * * @param env Environment * @param tid Transactor ID used to create node */ public TransactorNode(Environment env, TransactorID tid) { this.env = env; this.tid = tid; node = new PersistentEphemeralNode(env.getSharedResources().getCurator(), Mode.EPHEMERAL, getNodePath(), tid.toString().getBytes()); CuratorUtil.startAndWait(node, 10); status = TrStatus.OPEN; }