com.skype.connector
Class Connector

java.lang.Object
  extended by com.skype.connector.Connector
Direct Known Subclasses:
LinuxConnector, OSXConnector, TestConnector, Win32Connector, WindowsConnector

public abstract class Connector
extends Object

Base class for all platform specific connectors. A connector connects the Skype Java API with a running Skype client.

Author:
Koji Hisano

Nested Class Summary
static class Connector.Status
          Enumeration of the connector status.
 
Constructor Summary
protected Connector()
          Because this object should be a singleton the constructor is protected.
 
Method Summary
 void addConnectorListener(ConnectorListener listener)
          Adds the specified listener to this connector.
 void addConnectorListener(ConnectorListener listener, boolean checkAttached)
          Adds the specified listener to this connector.
 void addConnectorListener(ConnectorListener listener, boolean checkAttached, boolean isSynchronous)
          Adds the specified listener to this connector.
 Connector.Status connect()
          Tries to connect this connector to the Skype client.
protected abstract  Connector.Status connect(int timeout)
          Tries to connect this connector to the Skype client on the platform mechanism.
 void dispose()
          Disconnects from the Skype client and clean up the resources.
protected abstract  void disposeImpl()
          Disconnects from the Skype client and clean up the resources of the platfrom.
 String execute(String command)
          Executes the specified command and gets the response.
 void execute(String command, MessageProcessor processor)
          Deprecated. 
 String execute(String command, String responseHeader)
          Executes the specified command and gets the response.
 String execute(String command, String[] responseHeaders)
          Executes the specified command and gets the response.
protected  String execute(String command, String[] responseHeaders, boolean checkAttached)
          Executes the specified command and gets the response.
 String executeWithId(String command, String responseHeader)
          Executes the specified command and gets the response using a command ID.
 String executeWithoutTimeout(String command, String responseHeader)
          Executes the specified command and waits for the response without timeout.
protected  void fireMessageReceived(String message)
          Fires a message received event.
 String getApplicationName()
          Gets the application name used to get the access grant of Skype API.
 int getCommandTimeout()
          Gets the command reply timeout of this connector.
 int getConnectTimeout()
          Gets the connect timeout of this connector.
 PrintWriter getDebugOut()
          Gets the debug output stream.
 String getInstalledPath()
          Try to get the absolute path to the skype client.
static Connector getInstance()
          Initializes a platform specific connection.
 Connector.Status getStatus()
          Gets the status of this connector.
 String getStringProperty(String name)
          Gets the specified property value.
protected  void initialize()
          Initializes this connector.
protected abstract  void initializeImpl()
          Initializes the platform specific resources.
 boolean isRunning()
          Checks if the Skype client is running or not.
 void removeConnectorListener(ConnectorListener listener)
          Removes the specified listener from this connector.
protected  void sendApplicationName(String applicationName)
          Sends the application name to the Skype client.
protected abstract  void sendCommand(String command)
          Sends the specified command to the Skype client on the platform dependent communication layer.
protected  void sendProtocol()
          Sends the Skype API protocol version to use.
 void setApplicationName(String newApplicationName)
          Sets the application name used to get the access grant of Skype API.
 void setCommandTimeout(int newCommandTimeout)
          Sets the command reply timeout of this connector.
 void setConnectTimeout(int newConnectTimeout)
          Sets the connect timeout of this connector.
 void setDebug(boolean on)
          Enable or disable debug printing for more information.
 void setDebugOut(PrintStream newDebugOut)
          Sets the debug output stream.
 void setDebugOut(PrintWriter newDebugOut)
          Sets the debug output stream.
protected static void setInstance(Connector newInstance)
          Sets the instance of the connector for test cases.
protected  void setStatus(Connector.Status newStatus)
          Sets the status of this connector.
 void setStringProperty(String name, String value)
          Sets the specified property.
static void useJNIConnector(boolean on)
          To use the win32 dll instead of the SWT library please use this method.
 Future waitForEndWithId(String command, String responseHeader, NotificationChecker checker)
          Executes the specified command and gets the future using a command ID.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Connector

protected Connector()
Because this object should be a singleton the constructor is protected.

Method Detail

useJNIConnector

public static void useJNIConnector(boolean on)
To use the win32 dll instead of the SWT library please use this method.

Parameters:
on - If true the win32 connector will be used.

getInstance

public static Connector getInstance()
Initializes a platform specific connection. This method will select a connector based on the os.name. Windows has two versions see useJNIConnector.

Returns:
an initialized connection.

setInstance

protected static void setInstance(Connector newInstance)
                           throws ConnectorException
Sets the instance of the connector for test cases.

Parameters:
newInstance - The new instance.
Throws:
ConnectorException - thrown when instance is not valid.

getInstalledPath

public String getInstalledPath()
Try to get the absolute path to the skype client. Should be overridden for each platfrom specific connector. Not geranteed to work.

Returns:
The absolute path to the Skype client executable.

setDebug

public final void setDebug(boolean on)
                    throws ConnectorException
Enable or disable debug printing for more information.

Parameters:
on - if true debug output will be written to System.out
Throws:
ConnectorException - thrown when connection to Skype Client has gone bad.

setDebugOut

public final void setDebugOut(PrintWriter newDebugOut)
Sets the debug output stream.

Parameters:
newDebugOut - the new debug output stream
Throws:
NullPointerException - if the specified new debug out is null
See Also:
setDebugOut(PrintStream), getDebugOut()

setDebugOut

public final void setDebugOut(PrintStream newDebugOut)
Sets the debug output stream.

Parameters:
newDebugOut - the new debug output stream
Throws:
NullPointerException - if the specified new debug out is null
See Also:
setDebugOut(PrintWriter), getDebugOut()

getDebugOut

public final PrintWriter getDebugOut()
Gets the debug output stream.

Returns:
the current debug output stream
See Also:
setDebugOut(PrintWriter), setDebugOut(PrintStream)

setApplicationName

public final void setApplicationName(String newApplicationName)
Sets the application name used to get the access grant of Skype API. The specified name is what the User will see in the Skype API Allow/Deny dialog.

Parameters:
newApplicationName - the application name
Throws:
NullPointerException - if the specified application name is null
See Also:
getApplicationName()

getApplicationName

public final String getApplicationName()
Gets the application name used to get the access grant of Skype API.

Returns:
the application name
See Also:
setApplicationName(String)

setStatus

protected final void setStatus(Connector.Status newStatus)
Sets the status of this connector. After setting, an status changed event will be sent to the all listeners.

Parameters:
newValue - the new status
Throws:
NullPointerException - if the specified status is null
See Also:
getStatus()

getStatus

public final Connector.Status getStatus()
Gets the status of this connector.

Returns:
status the status of this connector
See Also:
setStatus(com.skype.connector.Connector.Status)

setConnectTimeout

public final void setConnectTimeout(int newConnectTimeout)
Sets the connect timeout of this connector.

Parameters:
newConnectTimeout - the new connect timeout in milliseconds
Throws:
IllegalArgumentException - if the new connect timeout is not more than 0
See Also:
getConnectTimeout()

getConnectTimeout

public final int getConnectTimeout()
Gets the connect timeout of this connector.

Returns:
the connect timeout in milliseconds
See Also:
setConnectTimeout(int)

setCommandTimeout

public final void setCommandTimeout(int newCommandTimeout)
Sets the command reply timeout of this connector.

Parameters:
newCommandTimeout - the new command reply timeout in milliseconds
Throws:
IllegalArgumentException - if the new command reply timeout is not more than 0
See Also:
getCommandTimeout()

getCommandTimeout

public final int getCommandTimeout()
Gets the command reply timeout of this connector.

Returns:
the command reply timeout in milliseconds
See Also:
setCommandTimeout(int)

connect

public final Connector.Status connect()
                               throws ConnectorException
Tries to connect this connector to the Skype client.

Returns:
the status after trying to connect.
Throws:
ConnectorException - if trying to connect failed
NotAttachedException - if the Skype client is not running

initialize

protected final void initialize()
                         throws ConnectorException
Initializes this connector.

Throws:
ConnectorException - if the initialization failed.

initializeImpl

protected abstract void initializeImpl()
                                throws ConnectorException
Initializes the platform specific resources.

Throws:
ConnectorException - if the initialization failed.

connect

protected abstract Connector.Status connect(int timeout)
                                     throws ConnectorException
Tries to connect this connector to the Skype client on the platform mechanism.

Parameters:
timeout - the connect timeout in milliseconds to use while connecting.
Returns:
the status after trying to connect
Throws:
ConnectorException - if the trying to connect failed.

sendApplicationName

protected void sendApplicationName(String applicationName)
                            throws ConnectorException
Sends the application name to the Skype client. The default implementation does nothing.

Parameters:
applicationName - the application name
Throws:
ConnectorException - if sending the specified application name failed

sendProtocol

protected void sendProtocol()
                     throws ConnectorException
Sends the Skype API protocol version to use. The default implementation uses the latest version of the Skype API.

Throws:
ConnectorException - if sending the protocol version failed

dispose

public final void dispose()
                   throws ConnectorException
Disconnects from the Skype client and clean up the resources.

Throws:
ConnectorException - if cleaning up the resources failed

disposeImpl

protected abstract void disposeImpl()
                             throws ConnectorException
Disconnects from the Skype client and clean up the resources of the platfrom.

Throws:
ConnectorException - if cleaning up the resources failed

isRunning

public boolean isRunning()
                  throws ConnectorException
Checks if the Skype client is running or not.

Returns:
true if the Skype client is runnunig; false otherwise
Throws:
ConnectorException - if checking the Skype client status failed

execute

@Deprecated
public final void execute(String command,
                                     MessageProcessor processor)
                   throws ConnectorException
Deprecated. 

Executes the specified command and handles the response by the specified message processor.

Parameters:
command - the command to execute
processor - the message processor
Throws:
NullPointerException - if the specified command or processor is null
ConnectorException - if executing the command failed

execute

public final String execute(String command)
                     throws ConnectorException
Executes the specified command and gets the response. It is better to use executeWithId(String, String) because it returns the accurate response.

Parameters:
command - the command to execute
Returns:
the response after execution
Throws:
NullPointerException - if the specified command is null
ConnectorException - if executing the command failed
See Also:
executeWithId(String, String)

executeWithId

public final String executeWithId(String command,
                                  String responseHeader)
                           throws ConnectorException
Executes the specified command and gets the response using a command ID.

Parameters:
command - the command to execute
responseHeader - the response header to get the accurate response
Returns:
the response after execution
Throws:
NullPointerException - if the specified command or responseHeader is null
ConnectorException - if executing the command failed

waitForEndWithId

public final Future waitForEndWithId(String command,
                                     String responseHeader,
                                     NotificationChecker checker)
                              throws ConnectorException
Executes the specified command and gets the future using a command ID.

Parameters:
command - the command to execute
responseHeader - the response header to get the accurate first response
checker - the notification checker to detect the end
Returns:
the future to wait for the end of the execution
Throws:
NullPointerException - if the specified command, responseHeader or checker is null
ConnectorException - if executing the command failed

executeWithoutTimeout

public final String executeWithoutTimeout(String command,
                                          String responseHeader)
                                   throws ConnectorException
Executes the specified command and waits for the response without timeout.

Parameters:
command - the command to execute
responseHeader - the response header to get the accurate response
Returns:
the response after execution
Throws:
NullPointerException - if the specified command or responseHeader is null
ConnectorException - if executing the command failed

execute

public final String execute(String command,
                            String responseHeader)
                     throws ConnectorException
Executes the specified command and gets the response.

Parameters:
command - the command to execute
responseHeader - the response header to get the accurate response
Returns:
the response after execution
Throws:
NullPointerException - if the specified command or responseHeader is null
ConnectorException - if executing the command failed

execute

public final String execute(String command,
                            String[] responseHeaders)
                     throws ConnectorException
Executes the specified command and gets the response.

Parameters:
command - the command to execute
responseHeaders - the response headers to get the accurate response
Returns:
the response after execution
Throws:
NullPointerException - if the specified command or responseHeader is null
ConnectorException - if executing the command failed

execute

protected final String execute(String command,
                               String[] responseHeaders,
                               boolean checkAttached)
                        throws ConnectorException
Executes the specified command and gets the response.

Parameters:
command - the command to execute
responseHeaders - the response headers to get the accurate response
checkAttached - if true check if this connector is attached
Returns:
the response after execution
Throws:
NullPointerException - if the specified command or responseHeader is null
ConnectorException - if executing the command failed

sendCommand

protected abstract void sendCommand(String command)
Sends the specified command to the Skype client on the platform dependent communication layer.

Parameters:
command - the command to be executed

addConnectorListener

public final void addConnectorListener(ConnectorListener listener)
                                throws ConnectorException
Adds the specified listener to this connector.

Parameters:
listener - the listener to be added
Throws:
NullPointerException - if the specified listener is null
ConnectorException - if trying to connect failed
See Also:
removeConnectorListener(ConnectorListener)

addConnectorListener

public final void addConnectorListener(ConnectorListener listener,
                                       boolean checkAttached)
                                throws ConnectorException
Adds the specified listener to this connector.

Parameters:
listener - the listener to be added
checkAttached - if true checks if this connector is attached
Throws:
NullPointerException - if the specified listener is null
ConnectorException - if trying to connect failed
See Also:
removeConnectorListener(ConnectorListener)

addConnectorListener

public final void addConnectorListener(ConnectorListener listener,
                                       boolean checkAttached,
                                       boolean isSynchronous)
                                throws ConnectorException
Adds the specified listener to this connector.

Parameters:
listener - the listener to be added
checkAttached - if true checks if this connector is attached
isSynchronous - if true the listener will be handled synchronously
Throws:
NullPointerException - if the specified listener is null
ConnectorException - if trying to connect failed
See Also:
removeConnectorListener(ConnectorListener)

removeConnectorListener

public final void removeConnectorListener(ConnectorListener listener)
Removes the specified listener from this connector.

Parameters:
listener - the listener to be removed
Throws:
NullPointerException - if the specified listener is null
See Also:
addConnectorListener(ConnectorListener)

fireMessageReceived

protected final void fireMessageReceived(String message)
Fires a message received event.

Parameters:
message - the message that triggered the event

setStringProperty

public final void setStringProperty(String name,
                                    String value)
Sets the specified property. If the specified value is null, the property is removed.

Parameters:
name - the property name
value - the property value
Throws:
NullPointerException - if the specified name is null
See Also:
getStringProperty(String)

getStringProperty

public final String getStringProperty(String name)
Gets the specified property value.

Parameters:
name - the property name
Returns:
the property value
Throws:
NullPointerException - if the specified name is null
See Also:
setStringProperty(String, String)


Copyright © 2004-2011. All Rights Reserved.