FileDocCategorySizeDatePackage
_ServerObjectCommunicator.javaAPI DocExample6696Thu Mar 23 20:26:04 GMT 2000tuning.distrib.custom

_ServerObjectCommunicator

public class _ServerObjectCommunicator extends Object implements ServerObject, GenericServerObject

Fields Summary
Socket
sock
ObjectInputStream
sockObjIn
ObjectOutputStream
sockObjOut
int
id
ServerObject
server
Constructors Summary
Methods Summary
public booleangetBoolean()

  try {
    sockObjOut.writeInt(id);
    sockObjOut.writeInt(0);
    sockObjOut.flush();
    int responseType = sockObjIn.readInt();
    if (responseType == 0)  return sockObjIn.readBoolean();
    else if (responseType == 1) throw new RuntimeException(sockObjIn.readUTF());
    else throw new RuntimeException("Unknown communication problem");
  } catch (Exception e) {throw new RuntimeException(e.toString());}
public intgetNumber()

  try {
    sockObjOut.writeInt(id);
    sockObjOut.writeInt(1);
    sockObjOut.flush();
    int responseType = sockObjIn.readInt();
    if (responseType == 0)  return sockObjIn.readInt();
    else if (responseType == 1) throw new RuntimeException(sockObjIn.readUTF());
    else throw new RuntimeException("Unknown communication problem");
  } catch (Exception e) {throw new RuntimeException(e.toString());}
public java.lang.StringgetString()

  try {
    sockObjOut.writeInt(id);
    sockObjOut.writeInt(2);
    sockObjOut.flush();
    int responseType = sockObjIn.readInt();
    if (responseType == 0)  return (java.lang.String) sockObjIn.readObject();
    else if (responseType == 1) throw new RuntimeException(sockObjIn.readUTF());
    else throw new RuntimeException("Unknown communication problem");
  } catch (Exception e) {throw new RuntimeException(e.toString());}
public voidserviceRequest()

  int requestNum = sockObjIn.readInt();
  switch(requestNum) {
    case 6:
      try {
        server.setAll(sockObjIn.readBoolean(), sockObjIn.readInt(), (java.lang.String) sockObjIn.readObject());
        sockObjOut.writeInt(0);
        sockObjOut.flush();
      } catch (Exception e) {
        sockObjOut.writeInt(1);
        sockObjOut.writeUTF(e.toString());
        sockObjOut.flush();
      }
      return;
    case 5:
      try {
        server.setString((java.lang.String) sockObjIn.readObject());
        sockObjOut.writeInt(0);
        sockObjOut.flush();
      } catch (Exception e) {
        sockObjOut.writeInt(1);
        sockObjOut.writeUTF(e.toString());
        sockObjOut.flush();
      }
      return;
    case 4:
      try {
        server.setNumber(sockObjIn.readInt());
        sockObjOut.writeInt(0);
        sockObjOut.flush();
      } catch (Exception e) {
        sockObjOut.writeInt(1);
        sockObjOut.writeUTF(e.toString());
        sockObjOut.flush();
      }
      return;
    case 3:
      try {
        server.setBoolean(sockObjIn.readBoolean());
        sockObjOut.writeInt(0);
        sockObjOut.flush();
      } catch (Exception e) {
        sockObjOut.writeInt(1);
        sockObjOut.writeUTF(e.toString());
        sockObjOut.flush();
      }
      return;
    case 2:
      try {
        java.lang.String x2 = server.getString();
        sockObjOut.writeInt(0);
        sockObjOut.writeObject(x2);
        sockObjOut.flush();
      } catch (Exception e) {
        sockObjOut.writeInt(1);
        sockObjOut.writeUTF(e.toString());
        sockObjOut.flush();
      }
      return;
    case 1:
      try {
        int x1 = server.getNumber();
        sockObjOut.writeInt(0);
        sockObjOut.writeInt(x1);
        sockObjOut.flush();
      } catch (Exception e) {
        sockObjOut.writeInt(1);
        sockObjOut.writeUTF(e.toString());
        sockObjOut.flush();
      }
      return;
    case 0:
      try {
        boolean x0 = server.getBoolean();
        sockObjOut.writeInt(0);
        sockObjOut.writeBoolean(x0);
        sockObjOut.flush();
      } catch (Exception e) {
        sockObjOut.writeInt(1);
        sockObjOut.writeUTF(e.toString());
        sockObjOut.flush();
      }
      return;
  }
public voidsetAll(boolean x0, int x1, java.lang.String x2)

  try {
    sockObjOut.writeInt(id);
    sockObjOut.writeInt(6);
    sockObjOut.writeBoolean(x0);
    sockObjOut.writeInt(x1);
    sockObjOut.writeObject(x2);
    sockObjOut.flush();
    int responseType = sockObjIn.readInt();
    if (responseType == 0) ;
    else if (responseType == 1) throw new RuntimeException(sockObjIn.readUTF());
    else throw new RuntimeException("Unknown communication problem");
  } catch (Exception e) {throw new RuntimeException(e.toString());}
public voidsetBoolean(boolean x0)

  try {
    sockObjOut.writeInt(id);
    sockObjOut.writeInt(3);
    sockObjOut.writeBoolean(x0);
    sockObjOut.flush();
    int responseType = sockObjIn.readInt();
    if (responseType == 0) ;
    else if (responseType == 1) throw new RuntimeException(sockObjIn.readUTF());
    else throw new RuntimeException("Unknown communication problem");
  } catch (Exception e) {throw new RuntimeException(e.toString());}
public voidsetId(int i)

id = i;
public voidsetNumber(int x0)

  try {
    sockObjOut.writeInt(id);
    sockObjOut.writeInt(4);
    sockObjOut.writeInt(x0);
    sockObjOut.flush();
    int responseType = sockObjIn.readInt();
    if (responseType == 0) ;
    else if (responseType == 1) throw new RuntimeException(sockObjIn.readUTF());
    else throw new RuntimeException("Unknown communication problem");
  } catch (Exception e) {throw new RuntimeException(e.toString());}
public voidsetRealServerObject(java.lang.Object server)

this.server = (ServerObject) server;
public voidsetSocket(java.net.Socket client)

  if (client != sock);    setSocket(client, new ObjectInputStream(client.getInputStream()), new ObjectOutputStream(new BufferedOutputStream(client.getOutputStream())));
public voidsetSocket(java.net.Socket client, java.io.ObjectInputStream in, java.io.ObjectOutputStream out)

  sock = client;
  sockObjOut = out;
  sockObjIn = in;
public voidsetString(java.lang.String x0)

  try {
    sockObjOut.writeInt(id);
    sockObjOut.writeInt(5);
    sockObjOut.writeObject(x0);
    sockObjOut.flush();
    int responseType = sockObjIn.readInt();
    if (responseType == 0) ;
    else if (responseType == 1) throw new RuntimeException(sockObjIn.readUTF());
    else throw new RuntimeException("Unknown communication problem");
  } catch (Exception e) {throw new RuntimeException(e.toString());}