KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > net > protocol > tcm > msgs > PingMessage


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.net.protocol.tcm.msgs;
5
6 import com.tc.bytes.TCByteBuffer;
7 import com.tc.io.TCByteBufferOutput;
8 import com.tc.io.TCByteBufferOutputStream;
9 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 JavaDoc;
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(MessageMonitor monitor, TCByteBufferOutput out, MessageChannel channel, TCMessageType type) {
30     super(monitor, out, channel, type);
31   }
32
33   public PingMessage(SessionID sessionID, MessageMonitor monitor, MessageChannel channel, TCMessageHeader header, TCByteBuffer[] data) {
34     super(sessionID, monitor, channel, header, data);
35   }
36
37   public PingMessage(MessageMonitor monitor) {
38     this(monitor, new TCByteBufferOutputStream(), null, TCMessageType.PING_MESSAGE);
39   }
40
41   public void initialize(SequenceGenerator sg) {
42     this.sequence = sg.getNextSequence();
43   }
44
45   public PingMessage createResponse() {
46     PingMessage rv = (PingMessage) getChannel().createMessage(TCMessageType.PING_MESSAGE);
47     rv.sequence = getSequence();
48     return rv;
49   }
50
51   protected void dehydrateValues() {
52     putNVPair(SEQUENCE, sequence);
53   }
54
55   protected boolean hydrateValue(byte name) throws IOException JavaDoc {
56     switch (name) {
57       case SEQUENCE:
58         sequence = getLongValue();
59         return true;
60       default:
61         return false;
62     }
63   }
64
65   public long getSequence() {
66     return this.sequence;
67   }
68 }
Popular Tags