@Override public SessionID createIdentifier() { final UUID uuid = UUID.randomUUID(); ByteBuffer bb = ByteBuffer.wrap(new byte[16]); bb.putLong(uuid.getMostSignificantBits()); bb.putLong(uuid.getLeastSignificantBits()); return SessionID.createSessionID(bb.array()); }
private void writeSessionId( final ChannelAssociation channelAssociation, final short invocationId, final SessionID sessionID, final Affinity hardAffinity) throws IOException { final byte[] sessionIdBytes = sessionID.getEncodedForm(); final DataOutputStream dataOutputStream; final MessageOutputStream messageOutputStream; try { messageOutputStream = channelAssociation.acquireChannelMessageOutputStream(); } catch (Exception e) { throw EjbMessages.MESSAGES.failedToOpenMessageOutputStream(e); } dataOutputStream = new DataOutputStream(messageOutputStream); try { // write out header dataOutputStream.writeByte(HEADER_SESSION_OPEN_RESPONSE); // write out invocation id dataOutputStream.writeShort(invocationId); // session id byte length PackedInteger.writePackedInteger(dataOutputStream, sessionIdBytes.length); // write out the session id bytes dataOutputStream.write(sessionIdBytes); // now marshal the hard affinity associated with this session final Marshaller marshaller = this.prepareForMarshalling(this.marshallerFactory, dataOutputStream); marshaller.writeObject(hardAffinity); // finish marshalling marshaller.finish(); } finally { channelAssociation.releaseChannelMessageOutputStream(messageOutputStream); dataOutputStream.close(); } }
@Override public SessionID readObject(ObjectInput input) throws IOException { byte[] encoded = new byte[input.readInt()]; input.readFully(encoded); return SessionID.createSessionID(encoded); }
@Override public void writeObject(ObjectOutput output, SessionID id) throws IOException { byte[] encoded = id.getEncodedForm(); output.writeInt(encoded.length); output.write(encoded); }