KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > quikj > server > framework > AceIPCConnRespMessage


1 package com.quikj.server.framework;
2
3 public class AceIPCConnRespMessage implements AceIPCMessageInterface
4 {
5     /*********************************************************************************/
6     //
7
// Octet 0: msg type
8
// Octet 1: status
9
// Octet 2: HB interval (msb)
10
// Octet 3: HB interval
11
// Octet 4: HB interval
12
// Octet 5: HB interval (lsb)
13
//
14
/*********************************************************************************/
15
16     // constants for status
17
public static final int STATUS_OK = 0;
18     public static final int STATUS_REFUSED = 1;
19     public static final int STATUS_TRY_LATER = 2;
20
21     // constructor for message received
22
protected AceIPCConnRespMessage (byte[] msg, int length) throws AceException
23     {
24     message = msg;
25     msgLength = length;
26     status = message [STATUS_OFFSET];
27     try
28         {
29         hbInterval = (int) AceInputSocketStream.octetsToIntMsbFirst (message,
30                                        HB_INTERVAL_OFFSET,
31                                        4);
32         }
33     catch (NumberFormatException JavaDoc ex)
34         {
35         throw new AceException ("NumberFormatException while decoding AceIPCConnRespMessage HB interval");
36         }
37     }
38     
39     // constructor for message to be sent
40
protected AceIPCConnRespMessage (int status, int hb_interval)
41     {
42     msgLength = MSG_HEADER_LENGTH;
43     message = new byte [msgLength];
44     this.status = status;
45     hbInterval = hb_interval;
46     
47     // fill in the message bytes
48
message [MSG_TYPE_OFFSET] = CONN_RESP_MSG;
49     message [STATUS_OFFSET] = (byte) status;
50     AceInputSocketStream.intToBytesMsbFirst (hbInterval, message, HB_INTERVAL_OFFSET);
51     }
52
53     public int getIPCMsgType()
54     {
55     return message[MSG_TYPE_OFFSET];
56     }
57     
58     public int getLength()
59     {
60     return msgLength;
61     }
62     
63     public String JavaDoc traceIPCMessage(boolean entire_message)
64     {
65     if (entire_message == true)
66         {
67         return (AceIPCMessage.dumpRawBytes (message, 0, msgLength));
68         }
69     else
70         {
71         return (new String JavaDoc ("CONNECT RESPONSE"));
72         }
73     }
74     
75     public byte[] getBytes()
76     {
77         return message;
78     }
79     
80     public int getStatus()
81     {
82         return status;
83     }
84
85     public int getHbInterval()
86     {
87         return hbInterval;
88     }
89     
90     private static final int MSG_HEADER_LENGTH = 6;
91     private static final int STATUS_OFFSET = 1;
92     private static final int HB_INTERVAL_OFFSET = 2;
93
94     private byte[] message;
95     private int msgLength;
96     private int status;
97     private int hbInterval;
98 }
99
Popular Tags