1 /**
2 This file is part of GoldenGate Project (named also GoldenGate or GG).
3
4 Copyright 2009, Frederic Bregier, and individual contributors by the @author
5 tags. See the COPYRIGHT.txt in the distribution for a full listing of
6 individual contributors.
7
8 All GoldenGate Project is free software: you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as published
10 by the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 GoldenGate is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GoldenGate . If not, see <http://www.gnu.org/licenses/>.
20 */
21 package openr66.protocol.localhandler.packet;
22
23 import openr66.protocol.exception.OpenR66ProtocolPacketException;
24
25 import org.jboss.netty.buffer.ChannelBuffer;
26 import org.jboss.netty.buffer.ChannelBuffers;
27
28 /**
29 * Startup Message class
30 *
31 * 1 localId (Integer): localId
32 *
33 * @author frederic bregier
34 */
35 public class StartupPacket extends AbstractLocalPacket {
36 private final Integer localId;
37
38 /**
39 * @param headerLength
40 * @param middleLength
41 * @param endLength
42 * @param buf
43 * @return the new ValidPacket from buffer
44 */
45 public static StartupPacket createFromBuffer(int headerLength,
46 int middleLength, int endLength, ChannelBuffer buf) {
47 Integer newId = buf.readInt();
48 return new StartupPacket(newId);
49 }
50
51 /**
52 * @param newId
53 */
54 public StartupPacket(Integer newId) {
55 localId = newId;
56 }
57
58 /*
59 * (non-Javadoc)
60 *
61 * @see openr66.protocol.localhandler.packet.AbstractLocalPacket#createEnd()
62 */
63 @Override
64 public void createEnd() throws OpenR66ProtocolPacketException {
65 end = ChannelBuffers.EMPTY_BUFFER;
66 }
67
68 /*
69 * (non-Javadoc)
70 *
71 * @see
72 * openr66.protocol.localhandler.packet.AbstractLocalPacket#createHeader()
73 */
74 @Override
75 public void createHeader() throws OpenR66ProtocolPacketException {
76 header = ChannelBuffers.buffer(4);
77 header.writeInt(localId);
78 }
79
80 /*
81 * (non-Javadoc)
82 *
83 * @see
84 * openr66.protocol.localhandler.packet.AbstractLocalPacket#createMiddle()
85 */
86 @Override
87 public void createMiddle() throws OpenR66ProtocolPacketException {
88 middle = ChannelBuffers.EMPTY_BUFFER;
89 }
90
91 /*
92 * (non-Javadoc)
93 *
94 * @see openr66.protocol.localhandler.packet.AbstractLocalPacket#toString()
95 */
96 @Override
97 public String toString() {
98 return "StartupPacket: " + localId;
99 }
100
101 @Override
102 public byte getType() {
103 return LocalPacketFactory.STARTUPPACKET;
104 }
105
106 /**
107 * @return the localId
108 */
109 public Integer getLocalId() {
110 return localId;
111 }
112
113 }