Commit | Line | Data |
---|---|---|
8e15b929 MK |
1 | /********************************************************************** |
2 | * Copyright (c) 2014 Ericsson | |
3 | * | |
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 | |
8 | * | |
9 | * Contributors: | |
10 | * Matthew Khouzam - Initial implementation | |
11 | **********************************************************************/ | |
12 | ||
9bc60be7 | 13 | package org.eclipse.tracecompass.internal.lttng2.control.core.relayd; |
8e15b929 MK |
14 | |
15 | import java.io.DataInputStream; | |
16 | import java.io.DataOutputStream; | |
17 | import java.io.IOException; | |
18 | import java.net.Socket; | |
19 | ||
9bc60be7 AM |
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; | |
8e15b929 MK |
26 | |
27 | /** | |
28 | * LTTng RelayD connector factory | |
29 | * | |
30 | * @author Matthew Khouzam | |
8e15b929 MK |
31 | */ |
32 | public final class LttngRelaydConnectorFactory { | |
33 | ||
34 | private LttngRelaydConnectorFactory() { | |
35 | } | |
36 | ||
37 | /** | |
38 | * Create a connection to a relayd | |
39 | * | |
40 | * @param myConnection | |
41 | * a connection to the relayd | |
42 | * | |
43 | * @return A relayd connector | |
44 | * @throws IOException | |
45 | * caused by invalid sockets | |
46 | */ | |
47 | public static ILttngRelaydConnector getNewConnector(Socket myConnection) throws IOException { | |
48 | DataOutputStream outNet = new DataOutputStream(myConnection.getOutputStream()); | |
49 | DataInputStream inNet = new DataInputStream(myConnection.getInputStream()); | |
50 | ||
51 | ViewerCommand connectCommand = new ViewerCommand(Command.VIEWER_CONNECT, ConnectResponse.SIZE, 0); | |
52 | ||
53 | outNet.write(connectCommand.serialize()); | |
54 | outNet.flush(); | |
55 | ||
fe25111b MAL |
56 | ConnectResponse payload = new ConnectResponse(0, 2, 4, ConnectionType.VIEWER_CLIENT_COMMAND); |
57 | outNet.write(payload.serialize()); | |
58 | outNet.flush(); | |
59 | ||
8e15b929 MK |
60 | ConnectResponse connectReply = new ConnectResponse(inNet); |
61 | switch (connectReply.getMajor()) { | |
62 | case 2: | |
63 | switch (connectReply.getMinor()) { | |
64 | case 0: | |
65 | case 1: | |
66 | case 2: | |
67 | case 3: | |
68 | return new LttngRelaydConnector_Unsupported(); | |
69 | case 4: | |
70 | default: | |
71 | return new LttngRelaydConnector_2_4(inNet, outNet); | |
72 | } | |
73 | default: | |
74 | return new LttngRelaydConnector_Unsupported(); | |
75 | } | |
76 | } | |
77 | } |