| 1 package com.quikj.server.framework; 2 3 public class AceIPCUserMessage implements AceIPCMessageInterface 4 { 5 6 19 20 protected AceIPCUserMessage (byte[] msg, int length) throws AceException 22 { 23 message = msg; 24 msgLength = length; 25 try 26 { 27 toThreadID = (int) AceInputSocketStream.octetsToIntMsbFirst (message, 28 TO_THREAD_ID_OFFSET, 29 4); 30 } 31 catch (NumberFormatException ex) 32 { 33 throw new AceException ("NumberFormatException while decoding AceIPCUserMessage To thread ID"); 34 } 35 try 36 { 37 fromThreadID = (int) AceInputSocketStream.octetsToIntMsbFirst (message, 38 FROM_THREAD_ID_OFFSET, 39 4); 40 } 41 catch (NumberFormatException ex) 42 { 43 throw new AceException ("NumberFormatException while decoding AceIPCUserMessage From thread ID"); 44 } 45 } 46 47 protected AceIPCUserMessage (int to_thread_id, int from_thread_id, 49 byte[] user_data, int offset, int user_data_length) 50 { 51 msgLength = MSG_HEADER_LENGTH + user_data_length; 52 message = new byte [msgLength]; 53 toThreadID = to_thread_id; 54 fromThreadID = from_thread_id; 55 56 message [MSG_TYPE_OFFSET] = USER_MSG; 58 AceInputSocketStream.intToBytesMsbFirst (toThreadID, message, TO_THREAD_ID_OFFSET); 59 AceInputSocketStream.intToBytesMsbFirst (fromThreadID, message, FROM_THREAD_ID_OFFSET); 60 61 System.arraycopy (user_data, offset, message, USER_DATA_OFFSET, user_data_length); 66 67 } 68 69 public int getIPCMsgType() 70 { 71 return message[MSG_TYPE_OFFSET]; 72 } 73 74 public int getLength() 75 { 76 return msgLength; 77 } 78 79 public String traceIPCMessage(boolean entire_message) 80 { 81 if (entire_message == true) 82 { 83 return (AceIPCMessage.dumpRawBytes (message, 0, msgLength)); 84 } 85 else 86 { 87 return (new String ("USER MESSAGE")); 88 } 89 } 90 91 public byte[] getBytes() 92 { 93 return message; 94 } 95 96 public int getToThreadID() 97 { 98 return toThreadID; 99 } 100 101 public int getFromThreadID() 102 { 103 return fromThreadID; 104 } 105 106 public int userDataOffset() 107 { 108 return USER_DATA_OFFSET; 109 } 110 111 public int userDataLength() 112 { 113 return (msgLength - USER_DATA_OFFSET); 114 } 115 116 private static final int MSG_HEADER_LENGTH = 9; 117 private static final int TO_THREAD_ID_OFFSET = 1; 118 private static final int FROM_THREAD_ID_OFFSET = 5; 119 private static final int USER_DATA_OFFSET = 9; 120 121 private byte[] message; 122 private int msgLength; 123 private int toThreadID; 124 private int fromThreadID; 125 } 126 | Popular Tags |