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
11 **********************************************************************/
13 package org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.relayd
;
15 import java
.io
.DataInputStream
;
16 import java
.io
.DataOutputStream
;
17 import java
.io
.IOException
;
18 import java
.net
.Socket
;
20 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.relayd
.impl
.LttngRelaydConnector_2_4
;
21 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.relayd
.impl
.LttngRelaydConnector_Unsupported
;
22 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.relayd
.lttngviewerCommands
.Command
;
23 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.relayd
.lttngviewerCommands
.ConnectResponse
;
24 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.relayd
.lttngviewerCommands
.ConnectionType
;
25 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.relayd
.lttngviewerCommands
.ViewerCommand
;
28 * LTTng RelayD connector factory
30 * @author Matthew Khouzam
32 public final class LttngRelaydConnectorFactory
{
34 private LttngRelaydConnectorFactory() {
38 * Create a connection to a relayd
41 * a connection to the relayd
43 * @return A relayd connector
45 * caused by invalid sockets
47 public static ILttngRelaydConnector
getNewConnector(Socket myConnection
) throws IOException
{
48 DataOutputStream outNet
= new DataOutputStream(myConnection
.getOutputStream());
49 DataInputStream inNet
= new DataInputStream(myConnection
.getInputStream());
51 ViewerCommand connectCommand
= new ViewerCommand(Command
.VIEWER_CONNECT
, ConnectResponse
.SIZE
, 0);
53 outNet
.write(connectCommand
.serialize());
56 ConnectResponse payload
= new ConnectResponse(0, 2, 4, ConnectionType
.VIEWER_CLIENT_COMMAND
);
57 outNet
.write(payload
.serialize());
60 ConnectResponse connectReply
= new ConnectResponse(inNet
);
61 switch (connectReply
.getMajor()) {
63 switch (connectReply
.getMinor()) {
68 return new LttngRelaydConnector_Unsupported();
71 return new LttngRelaydConnector_2_4(inNet
, outNet
);
74 return new LttngRelaydConnector_Unsupported();