1 /**********************************************************************
2 * Copyright (c) 2014 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Matthew Khouzam - Initial implementation and API
11 * Marc-Andre Laperle - Initial implementation and API
12 **********************************************************************/
14 package org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.relayd
.lttngviewerCommands
;
16 import java
.io
.DataInputStream
;
17 import java
.io
.IOException
;
18 import java
.nio
.ByteBuffer
;
19 import java
.nio
.ByteOrder
;
24 * @author Matthew Khouzam
27 public class ConnectResponse
implements IRelayResponse
, IRelayCommand
{
30 * Response or command size
32 * fViewerSessionId + fMajor + fMinor + fType
34 public static final int SIZE
= (Long
.SIZE
+ Integer
.SIZE
+ Integer
.SIZE
+ Integer
.SIZE
) / 8;
35 /** session id, counts from 1 and increments by session */
36 private final long fViewerSessionId
;
38 * Major version, hint, it's at least 2
40 private final int fMajor
;
42 * Minor version, hint, it's at least 4
44 private final int fMinor
;
46 * type of connect to {@link ConnectionType}
48 private final ConnectionType fType
;
51 * Connection response reply constructor
54 * the data input stream
58 public ConnectResponse(DataInputStream inStream
) throws IOException
{
59 byte data
[] = new byte[SIZE
];
60 inStream
.readFully(data
);
61 ByteBuffer bb
= ByteBuffer
.wrap(data
);
62 bb
.order(ByteOrder
.BIG_ENDIAN
);
63 fViewerSessionId
= bb
.getLong();
66 bb
.getInt(); // Should not be used, see http://bugs.lttng.org/issues/728
67 fType
= ConnectionType
.VIEWER_CLIENT_COMMAND
;
71 * Constructor for command
80 * the connection type, typically VIEWER_CLIENT_COMMAND
82 public ConnectResponse(long sessionID
, int major
, int minor
, ConnectionType connection
) {
83 fViewerSessionId
= sessionID
;
90 * get the major version
92 * @return the major version
94 public int getMajor() {
99 * get the minor version
101 * @return the minor version
103 public int getMinor() {
108 public byte[] serialize() {
109 byte data
[] = new byte[SIZE
];
110 ByteBuffer bb
= ByteBuffer
.wrap(data
);
111 bb
.order(ByteOrder
.BIG_ENDIAN
);
112 bb
.putLong(fViewerSessionId
);
115 bb
.putInt(fType
.getCommand());