Class | Tree | Deprecated | Index | Help
PREV CLASS | NEXT CLASS FRAMES  | NO FRAMES
SUMMARY:  INNER | FIELD | CONSTR | METHOD DETAIL:  FIELD | CONSTR | METHOD

Class CoBrowConnection

java.lang.Object
  |
  +--CoBrowConnection

public class CoBrowConnection
extends java.lang.Object
implements CoBrowService, java.lang.Runnable
The network object. Administers ONE connection to CoBrow server and provides interface for client/server interaction.


Field Summary
static int BAD_REQUEST
           
static java.lang.String HTTP_VERSION
           
static int NO_CONTENT
           
static int NOT_FOUND
           
static int NOT_MODIFIED
           
static int OK
           
 
Constructor Summary
CoBrowConnection(java.lang.String address, int port)
           
 
Method Summary
void close()
          Closes connection to CoBrow server.
void create(CoBrowObject cbObject)
          Registers userinterface with CoBrow server.
void delete(CoBrowObject cbObject, java.lang.String requestedObject)
          Unregisters userinterface from CoBrow server.
void get(CoBrowObject cbObject, java.lang.String requestedObject, java.lang.String[] parameters)
          Retrieves information from CoBrow server (overloaded; with additional parameters).
java.awt.Image getImage(java.applet.Applet applet, java.lang.String imageUrlString)
          Fetches an image.
void open(java.lang.String server, int port)
          Opens connection to CoBrow server.
void put(CoBrowObject cbObject, java.lang.String requestedObject, java.lang.String requestBody)
          Propagates information to CoBrow server.
int readMessage()
          Reads bytes from socket if available.
void run()
          Polls for incoming data.
void setId(java.lang.String id)
          Opens connection to CoBrow server.
void subscribe(CoBrowObject cbObject, java.lang.String requestedObject)
          Subscribes for information.
void unsubscribe(CoBrowObject cbObject, java.lang.String requestedObject)
          Unsubscribes for information.
java.lang.Integer writeMessage(CoBrowObject cbObject, java.lang.String command, java.lang.String requestedObject, byte[] requestBody)
          Sends a message over an HTTP connection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notifyAll, notify, toString, wait, wait, wait
 

Field Detail

HTTP_VERSION

protected static final java.lang.String HTTP_VERSION

OK

protected static final int OK

NO_CONTENT

protected static final int NO_CONTENT

NOT_MODIFIED

protected static final int NOT_MODIFIED

BAD_REQUEST

protected static final int BAD_REQUEST

NOT_FOUND

protected static final int NOT_FOUND
Constructor Detail

CoBrowConnection

public CoBrowConnection(java.lang.String address,
                        int port)
Parameters:
address - The IP address of the CoBrow server. REMARK: Must be the server the applet came from.
port - The port of the CoBrow service.
Method Detail

writeMessage

protected final java.lang.Integer writeMessage(CoBrowObject cbObject,
                                     java.lang.String command,
                                     java.lang.String requestedObject,
                                     byte[] requestBody)
                                       throws java.io.IOException
Sends a message over an HTTP connection.
Parameters:
cbObject - The CoBrowObject that issued the request.
command - The command to be executed, e.g. PUT, GET,...
requestedObject - The requested object, e.g. /users//properties
requestBody - The message body.
Returns:
The request number used for the message.
Throws:
java.io.IOException - If the message cannot be written onto the connection.

readMessage

protected final int readMessage()
                        throws java.io.IOException
Reads bytes from socket if available. Blocks on read if no bytes are available (enforces thread).
Returns:
The number of successfully read bytes, or error code.
Throws:
java.io.IOException - If the connection is not available any longer.

open

public final void open(java.lang.String server,
                       int port)
               throws java.io.IOException
Opens connection to CoBrow server.
Specified by:
open in interface CoBrowService
Parameters:
server - Name of the CoBrow server.
port - Port number the CoBrow server listens on for incoming requests.
Throws:
java.io.IOException - If opening connection fails.

close

public final void close()
                throws java.io.IOException
Closes connection to CoBrow server.
Specified by:
close in interface CoBrowService
Throws:
java.io.IOException - If shutting down connection fails.

setId

public final void setId(java.lang.String id)
Opens connection to CoBrow server.
Specified by:
setId in interface CoBrowService
Parameters:
id - The userinterface's id.

getImage

public java.awt.Image getImage(java.applet.Applet applet,
                      java.lang.String imageUrlString)
Fetches an image. Since Java applets are not allowed to connect to any other server than the one they came from, we use "redirectors". The "getImage" request has to be sent to the redirector, thus.
Specified by:
getImage in interface CoBrowService
Parameters:
applet -  
imageUrlString - The URL pointing to the image.
Returns:
The requested image.

create

public final void create(CoBrowObject cbObject)
                 throws java.io.IOException
Registers userinterface with CoBrow server.
Specified by:
create in interface CoBrowService
Parameters:
cbObject - The object invoking the request.
Throws:
java.io.IOException - If the request fails.

delete

public final void delete(CoBrowObject cbObject,
                         java.lang.String requestedObject)
                 throws java.io.IOException
Unregisters userinterface from CoBrow server.
Specified by:
delete in interface CoBrowService
Parameters:
cbObject - The object invoking the request.
requestedObject - The object which is to be unregistered.
Throws:
java.io.IOException - If the request fails.

get

public final void get(CoBrowObject cbObject,
                      java.lang.String requestedObject,
                      java.lang.String[] parameters)
              throws java.io.IOException
Retrieves information from CoBrow server (overloaded; with additional parameters).
Specified by:
get in interface CoBrowService
Parameters:
cbObject - The object invoking the request.
requestedObject - The object which is to be requested.
parameters - Additional parameters to be listed in the request header.
Throws:
java.io.IOException - If the request fails.

put

public final void put(CoBrowObject cbObject,
                      java.lang.String requestedObject,
                      java.lang.String requestBody)
              throws java.io.IOException
Propagates information to CoBrow server.
Specified by:
put in interface CoBrowService
Parameters:
cbObject - The object invoking the request.
requestedObject - The object which is to be requested.
requestBody - The data to be propagated to the server.
Throws:
java.io.IOException - If the request fails.

subscribe

public final void subscribe(CoBrowObject cbObject,
                            java.lang.String requestedObject)
                    throws java.io.IOException
Subscribes for information.
Specified by:
subscribe in interface CoBrowService
Parameters:
cbObject - The object invoking the request.
requestedObject - The object which is to be requested.
Throws:
java.io.IOException - If the request fails.

unsubscribe

public final void unsubscribe(CoBrowObject cbObject,
                              java.lang.String requestedObject)
                      throws java.io.IOException
Unsubscribes for information.
Specified by:
unsubscribe in interface CoBrowService
Parameters:
cbObject - The object invoking the request.
requestedObject - The object which is to be requested.
Throws:
java.io.IOException - If the request fails.

run

public void run()
Polls for incoming data.
Specified by:
run() in interface java.lang.Runnable

Class | Tree | Deprecated | Index | Help
PREV CLASS | NEXT CLASS FRAMES  | NO FRAMES
SUMMARY:  INNER | FIELD | CONSTR | METHOD DETAIL:  FIELD | CONSTR | METHOD