SCCT.JavaSubscriber
Class SCCT_Subject

java.lang.Object
  extended by SCCT.JavaSubscriber.SCCT_Subject

public class SCCT_Subject
extends java.lang.Object

It is a fundamental class of this library.
It has the task of handling the communication with the publisher, provides some methods to manage the connection and to send packages, and provides received data to registered Observer objects.


Constructor Summary
SCCT_Subject()
           
 
Method Summary
 int clearSelectedSourceList()
          The SCCT_Subject object won't listen to any data sources list.
 int closeCommunication()
          Sends to the publisher the request to close the communication.
 int getAwaitingPackages()
          Returns the number of packages awaiting in the sending queue.
static SCCT_Subject getInstance()
          This static method returns unique instance of SCCT_Subject (see Singleton pattern).
 int getLastPackageSent()
          Returns the packageNumber id of the last sent package.
 java.lang.String getSubscriberDescription()
          Returns the description used in the openCommunication method.
 int getTimeout()
          Returns the timeout used in the openCommunication method.
 boolean isConnected()
          Returns true value if it's connected, false if it doesn't.
 boolean isSourceFilterEnabled()
          Returns the sourceFilterEnabled flag used in the openCommunication method.
 void openCommunication(java.lang.String address, int port, java.lang.String APIKey)
          This function use as description, timeout and sourceFilterEnabled flag three properties.
 void openCommunication(java.lang.String address, int port, java.lang.String APIKey, java.lang.String description)
          Sets the timeout to default value and the source filter to false.
 void openCommunication(java.lang.String address, int port, java.lang.String APIKey, java.lang.String description, boolean sourceFilterEnabled)
          Sets the timeout to default value.
 void openCommunication(java.lang.String address, int port, java.lang.String APIKey, java.lang.String description, int timeout)
          Set the source filter to false.
 void openCommunication(java.lang.String address, int port, java.lang.String APIKey, java.lang.String description, int timeout, boolean sourceFilterEnabled)
          This method is very important because allows to open the communication with the publisher.
 void registerObserver(SCCT_Observer o)
          This method allows an observer to register itself in a list of observers for data receiving.
 int sendArray(SCCT_2DArrayPackage arrayPackage)
          Sends a SCCT_2DArrayPackage subclass to the publisher.
 int sendFile(SCCT_FilePackage fp)
          Sends a file to the publisher.
 int sendFilter(SCCT_Filter filter)
          Sends a SCCT_Filter subclass to the publisher.
 int sendImage(SCCT_ImagePackage ip)
          Sends an image to the publisher.
 int sendLocation(SCCT_LocationPackage lp)
          Sends a SCCT_LocationPackage to the publisher.
 int sendMessage(SCCT_MessagePackage messagePackage)
          Sends a custom message to the publisher.
 int sendMessage(java.lang.String message, int code)
          Sends a custom message to the publisher.
 int sendXml(SCCT_XmlPackage xmlPackage)
          Sends a custom xml to the publisher.
 int sendXml(java.lang.String xml)
          Sends a custom xml to the publisher.
 int setSelectedSourceList(java.util.ArrayList<java.lang.Integer> list)
          Sets a data sources list on which the SCCT_Subject object will listen.
 int setSelectedSourceList(int source)
          Set a single source of data on witch the SCCT_Subject object will listen.
 void setSourceFilterEnabled(boolean sourceFilterEnabled)
          Specifies whether the source filter is or is not enabled.
 void setSubscriberDescription(java.lang.String subscriberDescription)
          Sets the description to send the publisher in the openCommunication method.
 void setTimeout(int timeout)
          Sets the timeout in seconds to use in the openCommunication method.
 int start()
          Sends to the publisher the request to start data transmission.
 int stop()
          Sends to the publisher the request to stop data transmission.
 void unregisterObserver(SCCT_Observer o)
          This method allows to unregister an observer in a list of registered observers.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SCCT_Subject

public SCCT_Subject()
Method Detail

getInstance

public static SCCT_Subject getInstance()
This static method returns unique instance of SCCT_Subject (see Singleton pattern). This methods allows to share a single instance of SCCT_Subject among many classes easily.

Returns:
Unique instance of SCCT_Subject.

registerObserver

public void registerObserver(SCCT_Observer o)
This method allows an observer to register itself in a list of observers for data receiving.

Parameters:
o - It is the observer to register.

unregisterObserver

public void unregisterObserver(SCCT_Observer o)
This method allows to unregister an observer in a list of registered observers.

Parameters:
o - It is the observer to unregister.

getSubscriberDescription

public java.lang.String getSubscriberDescription()
Returns the description used in the openCommunication method. The default value of description is the name of the device used.

Returns:
the timeout used in openCommunication method.

setSubscriberDescription

public void setSubscriberDescription(java.lang.String subscriberDescription)
Sets the description to send the publisher in the openCommunication method.

Parameters:
subscriberDescription - The description that identify the subscriber.

getTimeout

public int getTimeout()
Returns the timeout used in the openCommunication method. The default value of timeout is 8 seconds. *This method is available only in PRO version.*

Returns:
the timeout used in openCommunication method.

setTimeout

public void setTimeout(int timeout)
Sets the timeout in seconds to use in the openCommunication method. *This method is available only in PRO version.*

Parameters:
timeout -

isSourceFilterEnabled

public boolean isSourceFilterEnabled()
Returns the sourceFilterEnabled flag used in the openCommunication method. The default value of sourceFilterEnabled is false. *This method is available only in PRO version.*

Returns:
the sourceFilterEnabled flag used in openCommunication method.

setSourceFilterEnabled

public void setSourceFilterEnabled(boolean sourceFilterEnabled)
Specifies whether the source filter is or is not enabled. *This method is available only in PRO version.*

Parameters:
sourceFilterEnabled -

getLastPackageSent

public int getLastPackageSent()
Returns the packageNumber id of the last sent package.

Returns:
the packageNumber id of the last sent package.

getAwaitingPackages

public int getAwaitingPackages()
Returns the number of packages awaiting in the sending queue.

Returns:
the number of packages in sending queue.

openCommunication

public void openCommunication(java.lang.String address,
                              int port,
                              java.lang.String APIKey,
                              java.lang.String description,
                              int timeout,
                              boolean sourceFilterEnabled)
                       throws java.io.IOException
This method is very important because allows to open the communication with the publisher.
It tries to open a communication with the publisher using the specified address and port.
If it fails or if the parameters are wrong, it throws an IOException.
If it is successful, it send to the publisher a message with the APIKey, the description, the timeout and the sourceFilterEnabled fields.
If the some of this parameters are wrong, the library send an errorPackage at all registered observer. The source filter is useful if you manage more than one data source.
If the source filter is disabled the SCCT_Subject object will receive the data of every source. Otherwise it will receive the data only from the selected sources.

Parameters:
address - The IP address or the name of the publisher.
port - The port number.
APIKey - The password for authenticate the client.
description - The description or the name of the client.
timeout - The timeout value in seconds. If the connectionHandler is lost and the timeout expired the library closes the communication and sends a timeout expired error to observers. This value must be bigger than one.
sourceFilterEnabled - Enables or disables the source filter.
Throws:
java.io.IOException - If you insert a wrong parameter or if the library can't establish a connectionHandler with publisher.
See Also:
*This method is available only in PRO version.*

openCommunication

public void openCommunication(java.lang.String address,
                              int port,
                              java.lang.String APIKey,
                              java.lang.String description,
                              boolean sourceFilterEnabled)
                       throws java.io.IOException
Sets the timeout to default value. *This method is available only in PRO version.*

Throws:
java.io.IOException
See Also:
openCommunication(String, int, String, String, int, boolean)

openCommunication

public void openCommunication(java.lang.String address,
                              int port,
                              java.lang.String APIKey,
                              java.lang.String description)
                       throws java.io.IOException
Sets the timeout to default value and the source filter to false.

Throws:
java.io.IOException
See Also:
openCommunication(String, int, String, String, int, boolean)

openCommunication

public void openCommunication(java.lang.String address,
                              int port,
                              java.lang.String APIKey,
                              java.lang.String description,
                              int timeout)
                       throws java.io.IOException
Set the source filter to false.

Throws:
java.io.IOException
See Also:
openCommunication(String, int, String, String, int, boolean)

openCommunication

public void openCommunication(java.lang.String address,
                              int port,
                              java.lang.String APIKey)
                       throws java.io.IOException
This function use as description, timeout and sourceFilterEnabled flag three properties. To get or change this properties use the appropriate getter and setter.

Parameters:
address - The IP address or the name of the publisher.
port - The port number.
APIKey - The password for authenticate the client.
Throws:
java.io.IOException - If you insert a wrong parameter or if the library can't establish a connectionHandler with publisher.
See Also:
getSubscriberDescription(), getTimeout(), isSourceFilterEnabled(), openCommunication(java.lang.String, int, java.lang.String, java.lang.String, int, boolean)

setSelectedSourceList

public int setSelectedSourceList(java.util.ArrayList<java.lang.Integer> list)
Sets a data sources list on which the SCCT_Subject object will listen.
If you set a new source list, the sources selected before will be cleared.
*This method is available only in PRO version.*

Parameters:
list - An ArrayList of integers that contains the numbers id of chosen sources.
Returns:
the progress packageNumber id that identify the package sent.

setSelectedSourceList

public int setSelectedSourceList(int source)
Set a single source of data on witch the SCCT_Subject object will listen.
If you set a new source, the sources selected before will be cleared.
*This method is available only in PRO version.*

Parameters:
source - The number id of chosen source.
Returns:
the progress packageNumber id that identify the package sent.
See Also:
setSelectedSourceList(ArrayList)

clearSelectedSourceList

public int clearSelectedSourceList()
The SCCT_Subject object won't listen to any data sources list. *This method is available only in PRO version.*

Returns:
the progress packageNumber id that identify the package sent.

start

public int start()
Sends to the publisher the request to start data transmission.

Returns:
the progress packageNumber id that identify the package sent.

stop

public int stop()
Sends to the publisher the request to stop data transmission.

Returns:
the progress packageNumber id that identify the package sent.

sendMessage

public int sendMessage(java.lang.String message,
                       int code)
Sends a custom message to the publisher.

Parameters:
message - The description of the message.
code - The code of the message.
Returns:
the progress packageNumber id that identify the package sent.

sendMessage

public int sendMessage(SCCT_MessagePackage messagePackage)
Sends a custom message to the publisher.

Parameters:
messagePackage - The SCCT_MessagePackage object to send.
Returns:
the progress packageNumber id that identify the package sent.

sendXml

public int sendXml(java.lang.String xml)
Sends a custom xml to the publisher. The library doesn't check if the xml is correct.

Parameters:
xml - The custom xml to send.
Returns:
the progress packageNumber id that identify the package sent.

sendXml

public int sendXml(SCCT_XmlPackage xmlPackage)
Sends a custom xml to the publisher. The library doesn't check if the xml is correct.

Parameters:
xmlPackage - The SCCT_XmlPackage to send.
Returns:
the progress packageNumber id that identify the package sent.

closeCommunication

public int closeCommunication()
Sends to the publisher the request to close the communication.

Returns:
the progress packageNumber id that identify the package sent.

isConnected

public boolean isConnected()
Returns true value if it's connected, false if it doesn't.

Returns:
the progress packageNumber id that identify the package sent.

sendFile

public int sendFile(SCCT_FilePackage fp)
Sends a file to the publisher. *This method is available only in PRO version.*

Parameters:
fp - The object containing the file to send.
Returns:
the progress packageNumber id that identify the package sent.
See Also:
SCCT_FilePackage

sendImage

public int sendImage(SCCT_ImagePackage ip)
Sends an image to the publisher. *This method is available only in PRO version.*

Parameters:
ip - The object containing the image to send.
Returns:
the progress packageNumber id that identify the package sent.
See Also:
SCCT_ImagePackage

sendLocation

public int sendLocation(SCCT_LocationPackage lp)
Sends a SCCT_LocationPackage to the publisher. *This method is available only in PRO version.*

Parameters:
lp - The SCCT_LocationPackage to send.
Returns:
the progress packageNumber id that identify the package sent.
See Also:
SCCT_LocationPackage

sendArray

public int sendArray(SCCT_2DArrayPackage arrayPackage)
Sends a SCCT_2DArrayPackage subclass to the publisher. *This method is available only in PRO version.*

Parameters:
arrayPackage - the array to send.
Returns:
the progress packageNumber id that identify the package sent.
See Also:
SCCT_2DArrayPackage

sendFilter

public int sendFilter(SCCT_Filter filter)
Sends a SCCT_Filter subclass to the publisher. *This method is available only in PRO version.*

Parameters:
filter - the filter to send to publisher.
Returns:
the progress packageNumber id that identify the package sent.
See Also:
SCCT_Filter