| 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 and API |
| 11 | * Marc-Andre Laperle - Initial implementation and API |
| 12 | **********************************************************************/ |
| 13 | |
| 14 | package org.eclipse.linuxtools.internal.lttng2.control.core.relayd.lttngviewerCommands; |
| 15 | |
| 16 | import java.io.DataInputStream; |
| 17 | import java.io.IOException; |
| 18 | import java.nio.ByteBuffer; |
| 19 | import java.nio.ByteOrder; |
| 20 | |
| 21 | /** |
| 22 | * Get viewer session response to command |
| 23 | * |
| 24 | * @author Matthew Khouzam |
| 25 | * @since 3.0 |
| 26 | */ |
| 27 | public class SessionResponse implements IRelayResponse { |
| 28 | |
| 29 | /** |
| 30 | * Response size |
| 31 | * |
| 32 | * fHostname + fSessionName + fId + fLiveTimer + fClients + fStreams |
| 33 | */ |
| 34 | public static final int SIZE = |
| 35 | LttngViewerCommands.LTTNG_VIEWER_HOST_NAME_MAX + LttngViewerCommands.LTTNG_VIEWER_NAME_MAX + (Long.SIZE + Integer.SIZE + Integer.SIZE + Integer.SIZE) / 8; |
| 36 | /** id of the session */ |
| 37 | private final long fId; |
| 38 | /** live timer */ |
| 39 | private final int fLiveTimer; |
| 40 | /** number of clients */ |
| 41 | private final int fClients; |
| 42 | /** number streams */ |
| 43 | private final int fStreams; |
| 44 | /** Hostname, like 'localhost' */ |
| 45 | private final String fHostname; |
| 46 | /** Session name, like 'streaming session' */ |
| 47 | private final String fSessionName; |
| 48 | |
| 49 | /** |
| 50 | * Session response network constructor |
| 51 | * |
| 52 | * @param inNet |
| 53 | * input network stream |
| 54 | * @throws IOException |
| 55 | * network error |
| 56 | */ |
| 57 | public SessionResponse(DataInputStream inNet) throws IOException { |
| 58 | byte[] data = new byte[SIZE]; |
| 59 | inNet.readFully(data); |
| 60 | ByteBuffer bb = ByteBuffer.wrap(data); |
| 61 | bb.order(ByteOrder.BIG_ENDIAN); |
| 62 | fId = bb.getLong(); |
| 63 | fLiveTimer = bb.getInt(); |
| 64 | fClients = bb.getInt(); |
| 65 | fStreams = bb.getInt(); |
| 66 | byte[] hostName = new byte[LttngViewerCommands.LTTNG_VIEWER_HOST_NAME_MAX]; |
| 67 | byte[] sessionName = new byte[LttngViewerCommands.LTTNG_VIEWER_NAME_MAX]; |
| 68 | bb.get(hostName, 0, hostName.length); |
| 69 | bb.get(sessionName, 0, sessionName.length); |
| 70 | fHostname = new String(hostName); |
| 71 | fSessionName = new String(sessionName); |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Gets the id of the session |
| 76 | * |
| 77 | * @return the id of the session |
| 78 | */ |
| 79 | public long getId() { |
| 80 | return fId; |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * Gets the live timer |
| 85 | * |
| 86 | * @return the live timer |
| 87 | */ |
| 88 | public int getLiveTimer() { |
| 89 | return fLiveTimer; |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * Gets the number of clients |
| 94 | * |
| 95 | * @return the number of clients |
| 96 | */ |
| 97 | public int getClients() { |
| 98 | return fClients; |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * Gets the number streams |
| 103 | * |
| 104 | * @return the number streams |
| 105 | */ |
| 106 | public int getStreams() { |
| 107 | return fStreams; |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * Gets the Hostname |
| 112 | * |
| 113 | * @return the Hostname |
| 114 | */ |
| 115 | public String getHostname() { |
| 116 | return fHostname; |
| 117 | } |
| 118 | |
| 119 | /** |
| 120 | * Gets the session name |
| 121 | * |
| 122 | * @return the session name |
| 123 | */ |
| 124 | public String getSessionName() { |
| 125 | return fSessionName; |
| 126 | } |
| 127 | |
| 128 | } |