/* The Java RTP/I latejoin service, Version 0.1 alpha.
*
* This library provides the functionality of a generic RTP/I latejoin service.
*
* Copyright (C) 2000 Juergen Vogel, Martin Mauve
* University of Mannheim / Germany
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Juergen Vogel
* Martin Mauve
*
* e-mail:
* {vogel,mauve}@informatik.uni-mannheim.de
*
* paper mail:
*
* Juergen Vogel
* Martin Mauve
* University of Mannheim
* Lehrstuhl Praktische Informatik IV
* L15, 16
* 68131 Mannheim
* Germany
*/
package rtpi.services.latejoin;
import rtpi.transport.TransportPacket;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
class ControlPacket {
static final int LATE_JOIN = 0;
static final int STATE_QUERY = 0;
static final int ACK_SERVER = 1;
static final int PACKET_SIZE = 24;
private int gsType;
private int type;
private int participantID; // sender participantID
private long subcomponentID;
private int tries; // nbr of tries
ControlPacket() {
}
ControlPacket(TransportPacket packet) {
ByteArrayInputStream bis = new ByteArrayInputStream(packet.getData());
DataInputStream dis = new DataInputStream(bis);
try {
gsType = dis.readInt();
type = dis.readInt();
participantID = dis.readInt();
subcomponentID = dis.readLong();
tries = dis.readInt();
dis.close();
bis.close();
} catch(IOException ex) {
System.err.println("ControlPacket::ControlPacket - Exception while parsing packet " + ex);
}
}
void setGenericServiceType(int type) {
gsType = type;
}
int getGenericServiceType() {
return gsType;
}
void setType(int t) {
type = t;
}
int getType() {
return type;
}
void setSubcomponentID(long id) {
subcomponentID = id;
}
long getSubcomponentID() {
return subcomponentID;
}
void setParticipantID(int s) {
participantID = s;
}
int getParticipantID() {
return participantID;
}
void setTries(int t) {
tries = t;
}
int getTries() {
return tries;
}
TransportPacket getEncodedPacket() {
byte[] data = new byte[PACKET_SIZE];
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(bos);
try {
dos.writeInt(gsType);
dos.writeInt(type);
dos.writeInt(participantID);
dos.writeLong(subcomponentID);
dos.writeInt(tries);
dos.flush();
bos.flush();
data = bos.toByteArray();
dos.close();
bos.close();
} catch(IOException ex) {
System.err.println("ControlPacket::getEncodedPacket - Exception while constructing packet " + ex);
}
if (data.length!=PACKET_SIZE) {
System.err.println("ControlPacket: illegal size of late join control channel packet!");
}
return new TransportPacket(PACKET_SIZE, data);
}
}