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
.impl
;
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
.ILttngRelaydConnector
;
21 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.relayd
.commands
.Command
;
22 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.relayd
.commands
.ConnectResponse
;
23 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.relayd
.commands
.ConnectionType
;
24 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.relayd
.commands
.ViewerCommand
;
27 * LTTng RelayD connector factory
29 * @author Matthew Khouzam
31 public final class LttngRelaydConnectorFactory
{
33 private LttngRelaydConnectorFactory() {
37 * Create a connection to a relayd
40 * a connection to the relayd
42 * @return A relayd connector
44 * caused by invalid sockets
46 public static ILttngRelaydConnector
getNewConnector(Socket myConnection
) throws IOException
{
47 DataOutputStream outNet
= new DataOutputStream(myConnection
.getOutputStream());
48 DataInputStream inNet
= new DataInputStream(myConnection
.getInputStream());
50 ViewerCommand connectCommand
= new ViewerCommand(Command
.VIEWER_CONNECT
, ConnectResponse
.SIZE
, 0);
52 outNet
.write(connectCommand
.serialize());
55 ConnectResponse payload
= new ConnectResponse(0, 2, 4, ConnectionType
.VIEWER_CLIENT_COMMAND
);
56 outNet
.write(payload
.serialize());
59 ConnectResponse connectReply
= new ConnectResponse(inNet
);
60 switch (connectReply
.getMajor()) {
62 switch (connectReply
.getMinor()) {
67 return new LttngRelaydConnector_Unsupported();
70 return new LttngRelaydConnector_2_4(inNet
, outNet
);
73 return new LttngRelaydConnector_Unsupported();