01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.net.protocol.tcm.msgs;
05:
06: import com.tc.bytes.TCByteBuffer;
07: import com.tc.io.TCByteBufferOutput;
08: import com.tc.io.TCByteBufferOutputStream;
09: import com.tc.net.protocol.tcm.MessageChannel;
10: import com.tc.net.protocol.tcm.MessageMonitor;
11: import com.tc.net.protocol.tcm.TCMessageHeader;
12: import com.tc.net.protocol.tcm.TCMessageType;
13: import com.tc.object.msg.DSOMessageBase;
14: import com.tc.object.session.SessionID;
15: import com.tc.util.SequenceGenerator;
16:
17: import java.io.IOException;
18:
19: /**
20: * A nice simple ping message. Mostly used for testing.
21: *
22: * @author teck
23: */
24: public class PingMessage extends DSOMessageBase {
25: private static final byte SEQUENCE = 1;
26:
27: private long sequence = -1;
28:
29: public PingMessage(SessionID sessionID, MessageMonitor monitor,
30: TCByteBufferOutput out, MessageChannel channel,
31: TCMessageType type) {
32: super (sessionID, monitor, out, channel, type);
33: }
34:
35: public PingMessage(SessionID sessionID, MessageMonitor monitor,
36: MessageChannel channel, TCMessageHeader header,
37: TCByteBuffer[] data) {
38: super (sessionID, monitor, channel, header, data);
39: }
40:
41: public PingMessage(MessageMonitor monitor) {
42: this (new SessionID(0), monitor, new TCByteBufferOutputStream(),
43: null, TCMessageType.PING_MESSAGE);
44: }
45:
46: public void initialize(SequenceGenerator sg) {
47: this .sequence = sg.getNextSequence();
48: }
49:
50: public PingMessage createResponse() {
51: PingMessage rv = (PingMessage) getChannel().createMessage(
52: TCMessageType.PING_MESSAGE);
53: rv.sequence = getSequence();
54: return rv;
55: }
56:
57: protected void dehydrateValues() {
58: putNVPair(SEQUENCE, sequence);
59: }
60:
61: protected boolean hydrateValue(byte name) throws IOException {
62: switch (name) {
63: case SEQUENCE:
64: sequence = getLongValue();
65: return true;
66: default:
67: return false;
68: }
69: }
70:
71: public long getSequence() {
72: return this.sequence;
73: }
74: }
|