protected LegacyJobImpl(LegacyJobLocation location, ByteSequence payload) { this.jobLocation = location; this.payload = new Buffer(payload.data, payload.offset, payload.length); }
static TransactionId convert(KahaTransactionInfo transactionInfo) { if (transactionInfo.hasLocalTransactionId()) { KahaLocalTransactionId tx = transactionInfo.getLocalTransactionId(); LocalTransactionId rc = new LocalTransactionId(); rc.setConnectionId(new ConnectionId(tx.getConnectionId())); rc.setValue(tx.getTransactionId()); return rc; } else { KahaXATransactionId tx = transactionInfo.getXaTransactionId(); XATransactionId rc = new XATransactionId(); rc.setBranchQualifier(tx.getBranchQualifier().toByteArray()); rc.setGlobalTransactionId(tx.getGlobalTransactionId().toByteArray()); rc.setFormatId(tx.getFormatId()); return rc; } } }
/** * Retrieve the scheduled Job's byte blob from the journal. * * @param location * The location of the KahaAddScheduledJobCommand that originated the Job. * * @return a ByteSequence containing the payload of the scheduled Job. * * @throws IOException if an error occurs while reading the payload value. */ protected ByteSequence getPayload(Location location) throws IOException { KahaAddScheduledJobCommand job = (KahaAddScheduledJobCommand) this.load(location); Buffer payload = job.getPayload(); return new ByteSequence(payload.getData(), payload.getOffset(), payload.getLength()); }
@Override public boolean equals(Object obj) { if (obj == this) return true; if (obj == null || obj.getClass() != Buffer.class) return false; return equals((Buffer) obj); }
@Override public int hashCode() { if( hashCode==0 ) { hashCode = super.hashCode();; } return hashCode; }
public Buffer compact() { if (length != data.length) { return new Buffer(toByteArray()); } return this; }
@SuppressWarnings("unchecked") private boolean recoverAckMessageFileMap() throws IOException { boolean requiresReplay = true; if (metadata.ackMessageFileMapLocation != null) { try { KahaAckMessageFileMapCommand audit = (KahaAckMessageFileMapCommand) load(metadata.ackMessageFileMapLocation); ObjectInputStream objectIn = new ObjectInputStream(audit.getAckMessageFileMap().newInput()); metadata.ackMessageFileMap = (Map<Integer, Set<Integer>>) objectIn.readObject(); metadata.ackMessageFileMapDirtyFlag.lazySet(true); requiresReplay = false; } catch (Exception e) { LOG.warn("Cannot recover ackMessageFileMap", e); } } // got no ackMessageFileMap stored so got to recreate via replay from start of the journal return requiresReplay; }
final public boolean contains(byte value) { return indexOf(value, 0) >= 0; }
@Override public boolean equals(Object obj) { if (obj == this) return true; if (obj == null || obj.getClass() != Buffer.class) return false; return equals((Buffer) obj); }
@Override public int hashCode() { if( hashCode==0 ) { hashCode = super.hashCode();; } return hashCode; }
public Buffer compact() { if (length != data.length) { return new Buffer(toByteArray()); } return this; }
@Override public void recover(TransactionRecoveryListener listener) throws IOException { for (Map.Entry<TransactionId, ArrayList<Operation>> entry : preparedTransactions.entrySet()) { XATransactionId xid = (XATransactionId)entry.getKey(); ArrayList<Message> messageList = new ArrayList<Message>(); ArrayList<MessageAck> ackList = new ArrayList<MessageAck>(); for (Operation op : entry.getValue()) { if( op.getClass() == AddOpperation.class ) { AddOpperation addOp = (AddOpperation)op; Message msg = (Message)wireFormat.unmarshal( new DataInputStream(addOp.getCommand().getMessage().newInput()) ); messageList.add(msg); } else { RemoveOpperation rmOp = (RemoveOpperation)op; MessageAck ack = (MessageAck)wireFormat.unmarshal( new DataInputStream(rmOp.getCommand().getAck().newInput()) ); ackList.add(ack); } } Message[] addedMessages = new Message[messageList.size()]; MessageAck[] acks = new MessageAck[ackList.size()]; messageList.toArray(addedMessages); ackList.toArray(acks); listener.recover(xid, addedMessages, acks); } } @Override
final public boolean contains(byte value) { return indexOf(value, 0) >= 0; }
private Location checkpointAckMessageFileMap() throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oout = new ObjectOutputStream(baos); oout.writeObject(metadata.ackMessageFileMap); oout.flush(); oout.close(); // using completion callback allows a disk sync to be avoided when enableJournalDiskSyncs = false Location location = store(new KahaAckMessageFileMapCommand().setAckMessageFileMap(new Buffer(baos.toByteArray())), nullCompletionCallback); try { location.getLatch().await(); } catch (InterruptedException e) { throw new InterruptedIOException(e.toString()); } return location; }
@Override public boolean equals(Object obj) { if (obj == this) return true; if (obj == null || obj.getClass() != Buffer.class) return false; return equals((Buffer) obj); }
@Override public int hashCode() { if( hashCode==0 ) { hashCode = super.hashCode();; } return hashCode; }