org.hackystat.sensorbase.client
Class SensorBaseClient

java.lang.Object
  extended by org.hackystat.sensorbase.client.SensorBaseClient

public class SensorBaseClient
extends java.lang.Object

Provides a high-level interface for Clients wishing to communicate with a SensorBase.

Author:
Philip Johnson

Nested Class Summary
static class SensorBaseClient.InvitationReply
          The possible responses to a Project invitation.
 
Field Summary
static java.lang.String SENSORBASECLIENT_TIMEOUT_KEY
          The System property key used to retrieve the default timeout value in milliseconds.
 
Constructor Summary
SensorBaseClient(java.lang.String host, java.lang.String email, java.lang.String password)
          Initializes a new SensorBaseClient, given the host, userEmail, and password.
 
Method Summary
 SensorBaseClient authenticate()
          Authenticates this user and password with the server.
 void clearCache()
          Delete all entries from this cache.
 void compressTables()
          Compresses the server database tables.
 void deleteProject(java.lang.String email, java.lang.String projectName)
          Deletes the Project given its owner and projectName.
 void deleteSensorData(java.lang.String email)
          Deletes all sensor data associated with the specified user.
 void deleteSensorData(java.lang.String email, javax.xml.datatype.XMLGregorianCalendar timestamp)
          Ensures that the SensorData instance with the specified user and tstamp is not on the server.
 void deleteSensorDataType(java.lang.String sdtName)
          Deletes the SDT given its name.
 void deleteUser(java.lang.String email)
          Deletes the User given their email.
 void enableCaching(java.lang.String cacheName, java.lang.String subDir, java.lang.Double maxLife, java.lang.Long capacity)
          Enables caching in this client.
 void enableHttpTracing(boolean enable)
          When passed true, future HTTP calls using this client instance will print out information on the request and response.
 MultiDayProjectSummary getMonthProjectSummary(java.lang.String owner, java.lang.String projectName, int year, int month)
          Returns a MultiDayProjectSummary for the specified project, year, and month (zero based).
 MultiDayProjectSummary getMultiDayProjectSummary(java.lang.String owner, java.lang.String projectName, javax.xml.datatype.XMLGregorianCalendar startTime, int numDays)
          Returns a MultiDayProjectSummary for the specified interval of days.
 Project getProject(ProjectRef ref)
          Returns the named Project associated with the ProjectRef.
 Project getProject(java.lang.String email, java.lang.String projectName)
          Returns the Project from this server.
 ProjectIndex getProjectIndex()
          Returns the index of all Projects from this server.
 ProjectIndex getProjectIndex(java.lang.String email)
          Returns the index of all Projects from this server associated with this user.
 SensorDataIndex getProjectSensorData(java.lang.String owner, java.lang.String projectName)
          Returns a SensorDataIndex representing all the SensorData for this Project.
 SensorDataIndex getProjectSensorData(java.lang.String owner, java.lang.String projectName, javax.xml.datatype.XMLGregorianCalendar startTime, javax.xml.datatype.XMLGregorianCalendar endTime)
          Returns a SensorDataIndex representing the SensorData for the Project during the time interval.
 SensorDataIndex getProjectSensorData(java.lang.String owner, java.lang.String projectName, javax.xml.datatype.XMLGregorianCalendar startTime, javax.xml.datatype.XMLGregorianCalendar endTime, int startIndex, int maxInstances)
          Returns a SensorDataIndex representing the SensorData with the startIndex and maxInstances for the Project during the time interval.
 SensorDataIndex getProjectSensorData(java.lang.String owner, java.lang.String projectName, javax.xml.datatype.XMLGregorianCalendar startTime, javax.xml.datatype.XMLGregorianCalendar endTime, java.lang.String sdt)
          Returns a SensorDataIndex representing the SensorData with the given SDT for the Project during the time interval.
 SensorDataIndex getProjectSensorData(java.lang.String owner, java.lang.String projectName, javax.xml.datatype.XMLGregorianCalendar startTime, javax.xml.datatype.XMLGregorianCalendar endTime, java.lang.String sdt, java.lang.String tool)
          Returns a SensorDataIndex representing the SensorData with the given SDT for the Project during the time interval.
 SensorDataIndex getProjectSensorDataSnapshot(java.lang.String owner, java.lang.String projectName, javax.xml.datatype.XMLGregorianCalendar startTime, javax.xml.datatype.XMLGregorianCalendar endTime, java.lang.String sdt)
          Returns a SensorDataIndex containing a snapshot of the sensor data for the given project and sdt during the specified time interval.
 SensorDataIndex getProjectSensorDataSnapshot(java.lang.String owner, java.lang.String projectName, javax.xml.datatype.XMLGregorianCalendar startTime, javax.xml.datatype.XMLGregorianCalendar endTime, java.lang.String sdt, java.lang.String tool)
          Returns a SensorDataIndex containing a snapshot of the sensor data for the given project, sdt and tool during the specified time interval.
 ProjectSummary getProjectSummary(java.lang.String owner, java.lang.String projectName, javax.xml.datatype.XMLGregorianCalendar startTime, javax.xml.datatype.XMLGregorianCalendar endTime)
          Returns a ProjectSummary representing a summary of the number of sensor data instances of each type for the given interval.
 SensorData getSensorData(SensorDataRef ref)
          Returns the named SensorData associated with the SensorDataRef.
 SensorData getSensorData(java.lang.String uriString)
          Returns the SensorData for this user from this server given the passed uriString suffix.
 SensorData getSensorData(java.lang.String email, javax.xml.datatype.XMLGregorianCalendar timestamp)
          Returns the SensorData for this user from this server with the specified timestamp.
 SensorDataIndex getSensorDataIndex()
          Returns the index of SensorData from this server.
 SensorDataIndex getSensorDataIndex(java.lang.String email)
          Returns the index of SensorData for this user from this server.
 SensorDataIndex getSensorDataIndex(java.lang.String email, java.lang.String sdtName)
          Returns the index of SensorData for this user from this server with the specified SDT.
 SensorDataIndex getSensorDataIndexLastMod(java.lang.String email, javax.xml.datatype.XMLGregorianCalendar lastModStartTime, javax.xml.datatype.XMLGregorianCalendar lastModEndTime)
          Returns an index to SensorData for the specified user of all sensor data that have arrived at the server since the specified start and end times.
 SensorDataType getSensorDataType(SensorDataTypeRef ref)
          Returns the named SensorDataType associated with the SensorDataTypeRef.
 SensorDataType getSensorDataType(java.lang.String sdtName)
          Returns the named SensorDataType from this server.
 SensorDataTypeIndex getSensorDataTypeIndex()
          Returns the index of SensorDataTypes from this server.
 org.restlet.data.Response getUri(java.lang.String uriString)
          GETs the URI string and returns the Restlet Response if the server indicates success.
 User getUser()
          Returns the User instance associated with this SensorBaseClient instance.
 User getUser(java.lang.String email)
          Returns the named User from this server.
 User getUser(UserRef ref)
          Returns the named User associated with the UserRef.
 UserIndex getUserIndex()
          Returns the index of Users from this server.
 void indexTables()
          Indexes the server database tables.
 boolean inProject(java.lang.String email, java.lang.String projectName)
          True if the current user is the owner, member, or spectator of the specified project.
 Project invite(java.lang.String email, java.lang.String projectName)
          Invites the user indicated via their email address to the named project owned by this user.
static boolean isHost(java.lang.String host)
          Returns true if the passed host is a SensorBase host.
static boolean isRegistered(java.lang.String host, java.lang.String email, java.lang.String password)
          Returns true if the user and password is registered as a user with this host.
 SensorData makeSensorData(java.util.Map<java.lang.String,java.lang.String> keyValMap)
          Provides an easy way to construct SensorData instances.
 void putProject(Project project)
          Creates the passed Project on the server.
 void putSensorData(SensorData data)
          Creates the passed SensorData on the server.
 void putSensorDataBatch(SensorDatas data)
          Creates the passed batch of SensorData on the server.
 void putSensorDataType(SensorDataType sdt)
          Creates the passed SDT on the server.
static void registerUser(java.lang.String host, java.lang.String email)
          Registers the given user email with the given SensorBase.
 void renameProject(java.lang.String owner, java.lang.String projectName, java.lang.String newProjectName)
          Renames the project.
 void reply(java.lang.String owner, java.lang.String projectName, SensorBaseClient.InvitationReply reply)
          Accepts the invitation to be a member of the project owned by owner.
 int rowCount(java.lang.String table)
          Gets the rowcount for the specified table.
 void setTimeout(int milliseconds)
          Attempts to provide a timeout value for this SensorBaseClient.
 void updateUserProperties(java.lang.String email, Properties properties)
          Updates the specified user's properties.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SENSORBASECLIENT_TIMEOUT_KEY

public static final java.lang.String SENSORBASECLIENT_TIMEOUT_KEY
The System property key used to retrieve the default timeout value in milliseconds.

See Also:
Constant Field Values
Constructor Detail

SensorBaseClient

public SensorBaseClient(java.lang.String host,
                        java.lang.String email,
                        java.lang.String password)
Initializes a new SensorBaseClient, given the host, userEmail, and password.

Parameters:
host - The host, such as 'http://localhost:9876/sensorbase'.
email - The user's email that we will use for authentication.
password - The password we will use for authentication.
Method Detail

setTimeout

public final void setTimeout(int milliseconds)
Attempts to provide a timeout value for this SensorBaseClient.

Parameters:
milliseconds - The number of milliseconds to wait before timing out.

enableHttpTracing

public void enableHttpTracing(boolean enable)
When passed true, future HTTP calls using this client instance will print out information on the request and response.

Parameters:
enable - If true, trace output will be generated.

authenticate

public SensorBaseClient authenticate()
                              throws SensorBaseClientException
Authenticates this user and password with the server.

Returns:
This SensorBaseClient instance.
Throws:
SensorBaseClientException - If authentication is not successful.

makeSensorData

public SensorData makeSensorData(java.util.Map<java.lang.String,java.lang.String> keyValMap)
                          throws SensorBaseClientException
Provides an easy way to construct SensorData instances. The keyValMap is processed and the key-value pairs are processed in the following way. Throws an exception if Timestamp or Runtime are supplied but can't be parsed into an XMLGregorianCalendar instance.

Parameters:
keyValMap - The map of key-value pairs corresponding to SensorData fields and properties.
Returns:
A SensorData instance.
Throws:
SensorBaseClientException - If errors occur parsing the contents of the keyValMap.

getSensorDataTypeIndex

public SensorDataTypeIndex getSensorDataTypeIndex()
                                           throws SensorBaseClientException
Returns the index of SensorDataTypes from this server.

Returns:
The SensorDataTypeIndex instance.
Throws:
SensorBaseClientException - If the server does not return the Index or returns an index that cannot be marshalled into Java SensorDataTypeIndex instance.

getSensorDataType

public SensorDataType getSensorDataType(java.lang.String sdtName)
                                 throws SensorBaseClientException
Returns the named SensorDataType from this server.

Parameters:
sdtName - The SDT name.
Returns:
The SensorDataType instance.
Throws:
SensorBaseClientException - If the server does not return the SDT or returns something that cannot be marshalled into Java SensorDataType instance.

getSensorDataType

public SensorDataType getSensorDataType(SensorDataTypeRef ref)
                                 throws SensorBaseClientException
Returns the named SensorDataType associated with the SensorDataTypeRef.

Parameters:
ref - The SensorDataTypeRef instance
Returns:
The SensorDataType instance.
Throws:
SensorBaseClientException - If the server does not return the SDT or returns something that cannot be marshalled into Java SensorDataType instance.

putSensorDataType

public void putSensorDataType(SensorDataType sdt)
                       throws SensorBaseClientException
Creates the passed SDT on the server. This is an admin-only operation.

Parameters:
sdt - The SDT to create.
Throws:
SensorBaseClientException - If the user is not the admin or if there is some problem with the SDT instance.

deleteSensorDataType

public void deleteSensorDataType(java.lang.String sdtName)
                          throws SensorBaseClientException
Deletes the SDT given its name.

Parameters:
sdtName - The name of the SDT to delete.
Throws:
SensorBaseClientException - If the server does not indicate success.

getUserIndex

public UserIndex getUserIndex()
                       throws SensorBaseClientException
Returns the index of Users from this server. This is an admin-only operation.

Returns:
The UserIndex instance.
Throws:
SensorBaseClientException - If the server does not return the Index or returns an index that cannot be marshalled into Java UserIndex instance.

getUser

public User getUser()
             throws SensorBaseClientException
Returns the User instance associated with this SensorBaseClient instance. Requires a HTTP call to the SensorBase.

Returns:
The User instance for the user associated with this SensorBaseClient.
Throws:
SensorBaseClientException - If problems occur.

getUser

public User getUser(java.lang.String email)
             throws SensorBaseClientException
Returns the named User from this server.

Parameters:
email - The user email.
Returns:
The User.
Throws:
SensorBaseClientException - If the server does not return the SDT or returns something that cannot be marshalled into Java User instance.

getUser

public User getUser(UserRef ref)
             throws SensorBaseClientException
Returns the named User associated with the UserRef.

Parameters:
ref - The UserRef instance
Returns:
The User instance.
Throws:
SensorBaseClientException - If the server does not return the user or returns something that cannot be marshalled into Java User instance.

deleteUser

public void deleteUser(java.lang.String email)
                throws SensorBaseClientException
Deletes the User given their email.

Parameters:
email - The email of the User to delete.
Throws:
SensorBaseClientException - If the server does not indicate success.

updateUserProperties

public void updateUserProperties(java.lang.String email,
                                 Properties properties)
                          throws SensorBaseClientException
Updates the specified user's properties.

Parameters:
email - The email of the User whose properties are to be deleted.
properties - The properties to post.
Throws:
SensorBaseClientException - If the server does not indicate success.

getUri

public org.restlet.data.Response getUri(java.lang.String uriString)
                                 throws SensorBaseClientException
GETs the URI string and returns the Restlet Response if the server indicates success.

Parameters:
uriString - The URI String, such as "http://localhost:9876/sensorbase/sensordatatypes".
Returns:
The response instance if the GET request succeeded.
Throws:
SensorBaseClientException - If the server indicates that a problem occurred.

getSensorDataIndex

public SensorDataIndex getSensorDataIndex()
                                   throws SensorBaseClientException
Returns the index of SensorData from this server. This is an admin-only operation.

Returns:
The SensorDataIndex instance.
Throws:
SensorBaseClientException - If the server does not return the Index or returns an index that cannot be marshalled into Java SensorDataIndex instance.

getSensorDataIndex

public SensorDataIndex getSensorDataIndex(java.lang.String email)
                                   throws SensorBaseClientException
Returns the index of SensorData for this user from this server.

Parameters:
email - The user email.
Returns:
The SensorDataIndex instance.
Throws:
SensorBaseClientException - If the server does not return the Index or returns an index that cannot be marshalled into Java SensorDataIndex instance.

getSensorDataIndex

public SensorDataIndex getSensorDataIndex(java.lang.String email,
                                          java.lang.String sdtName)
                                   throws SensorBaseClientException
Returns the index of SensorData for this user from this server with the specified SDT.

Parameters:
email - The user email.
sdtName - The name of the SDT whose SensorData is to be returned.
Returns:
The SensorDataIndex instance.
Throws:
SensorBaseClientException - If the server does not return the Index or returns an index that cannot be marshalled into Java SensorDataIndex instance.

getSensorDataIndexLastMod

public SensorDataIndex getSensorDataIndexLastMod(java.lang.String email,
                                                 javax.xml.datatype.XMLGregorianCalendar lastModStartTime,
                                                 javax.xml.datatype.XMLGregorianCalendar lastModEndTime)
                                          throws SensorBaseClientException
Returns an index to SensorData for the specified user of all sensor data that have arrived at the server since the specified start and end times. Uses the LastMod field to determine what data will be retrieved.

Note that data could be sent recently with a Timestamp (as opposed to LastMod field) from far back in the past, and the index will include references to such data. This method thus differs from all other SensorDataIndex-returning methods, because the others compare passed timestamp values to the Timestamp associated with the moment at which a sensor data instance is created, not the moment it ends up being received by the server.

This method is intended for use by user interface facilities such as the SensorDataViewer that wish to monitor the arrival of data at the SensorBase.

Parameters:
email - The user email.
lastModStartTime - A timestamp used to determine the start time of data to get.
lastModEndTime - A timestamp used to determine the end time of data to get.
Returns:
The SensorDataIndex instance.
Throws:
SensorBaseClientException - If the server does not return the Index or returns an index that cannot be marshalled into Java SensorDataIndex instance.

getSensorData

public SensorData getSensorData(java.lang.String email,
                                javax.xml.datatype.XMLGregorianCalendar timestamp)
                         throws SensorBaseClientException
Returns the SensorData for this user from this server with the specified timestamp. Uses the cache if enabled.

Parameters:
email - The user email.
timestamp - The timestamp.
Returns:
The SensorData instance.
Throws:
SensorBaseClientException - If the server does not return the success code or returns a String that cannot be marshalled into Java SensorData instance.

getSensorData

public SensorData getSensorData(java.lang.String uriString)
                         throws SensorBaseClientException
Returns the SensorData for this user from this server given the passed uriString suffix.

Parameters:
uriString - A string that when prefixed with the sensorbase host should return a SensorData instance in XML format. A string such as "http://localhost:9876/sensorbase" will be prefixed to the uriString.
Returns:
The SensorData instance.
Throws:
SensorBaseClientException - If the server does not return the success code or returns a String that cannot be marshalled into Java SensorData instance.

getSensorData

public SensorData getSensorData(SensorDataRef ref)
                         throws SensorBaseClientException
Returns the named SensorData associated with the SensorDataRef.

Parameters:
ref - The SensorDataRef instance
Returns:
The SensorData instance.
Throws:
SensorBaseClientException - If the server does not return the data or returns something that cannot be marshalled into Java SensorData instance.

putSensorData

public void putSensorData(SensorData data)
                   throws SensorBaseClientException
Creates the passed SensorData on the server.

Parameters:
data - The sensor data to create.
Throws:
SensorBaseClientException - If problems occur posting this data.

putSensorDataBatch

public void putSensorDataBatch(SensorDatas data)
                        throws SensorBaseClientException
Creates the passed batch of SensorData on the server. Assumes that all of them have the same owner field, and that batch is non-empty.

Parameters:
data - The sensor data batch to create, represented as a SensorDatas instance.
Throws:
SensorBaseClientException - If problems occur posting this data.

deleteSensorData

public void deleteSensorData(java.lang.String email,
                             javax.xml.datatype.XMLGregorianCalendar timestamp)
                      throws SensorBaseClientException
Ensures that the SensorData instance with the specified user and tstamp is not on the server. Returns success even if the SensorData instance did not exist on the server.

Parameters:
email - The email of the User.
timestamp - The timestamp of the sensor data.
Throws:
SensorBaseClientException - If the server does not indicate success.

deleteSensorData

public void deleteSensorData(java.lang.String email)
                      throws SensorBaseClientException
Deletes all sensor data associated with the specified user. Note that the user must be a test user. Returns success even if the user had no sensor data.

Parameters:
email - The email of the User.
Throws:
SensorBaseClientException - If the server does not indicate success.

getProjectIndex

public ProjectIndex getProjectIndex()
                             throws SensorBaseClientException
Returns the index of all Projects from this server. This is an admin-only operation.

Returns:
The ProjectIndex instance.
Throws:
SensorBaseClientException - If the server does not return the Index or returns an index that cannot be marshalled into Java ProjectIndex instance.

getProjectIndex

public ProjectIndex getProjectIndex(java.lang.String email)
                             throws SensorBaseClientException
Returns the index of all Projects from this server associated with this user. This includes the projects that this user owns, that this user is a member of, and that this user has been invited to participate in as a member (but has not yet accepted or declined.)

Parameters:
email - The user email.
Returns:
The ProjectIndex instance.
Throws:
SensorBaseClientException - If the server does not return the Index or returns an index that cannot be marshalled into Java ProjectIndex instance.

getProject

public Project getProject(java.lang.String email,
                          java.lang.String projectName)
                   throws SensorBaseClientException
Returns the Project from this server.

Parameters:
email - The user email.
projectName - The project name.
Returns:
The Project
Throws:
SensorBaseClientException - If the server does not return success or returns something that cannot be marshalled into Java Project instance.

inProject

public boolean inProject(java.lang.String email,
                         java.lang.String projectName)
True if the current user is the owner, member, or spectator of the specified project. If caching is enabled, then we cache the retrieved project definition for 3 minutes when this client is an owner, member, or spectator so that subsequent retrievals don't require an http access.

Parameters:
email - The email address of the project owner.
projectName - The name of the project.
Returns:
True if this user is now a member of the

invite

public Project invite(java.lang.String email,
                      java.lang.String projectName)
               throws SensorBaseClientException
Invites the user indicated via their email address to the named project owned by this user. Has no effect if the user is already an invited member. Returns the updated project representation.

Parameters:
email - The user to be invited to this project.
projectName - The project name.
Returns:
The project representation as a result of the invitation.
Throws:
SensorBaseClientException - If the server does not return success.

reply

public void reply(java.lang.String owner,
                  java.lang.String projectName,
                  SensorBaseClient.InvitationReply reply)
           throws SensorBaseClientException
Accepts the invitation to be a member of the project owned by owner.

Parameters:
owner - The owner of the project that this user has been invited into
projectName - the name of the project.
reply - The reply, either ACCEPT or DECLINE.
Throws:
SensorBaseClientException - If the server returns an error from this acceptance, for example if the user has not actually been invited.

renameProject

public void renameProject(java.lang.String owner,
                          java.lang.String projectName,
                          java.lang.String newProjectName)
                   throws SensorBaseClientException
Renames the project.

Parameters:
owner - The owner of the project to be renamed.
projectName - The current name of the project.
newProjectName - The new name of the project.
Throws:
SensorBaseClientException - If the server returns an error from this acceptance, for example if the new project name is not unique.

getProject

public Project getProject(ProjectRef ref)
                   throws SensorBaseClientException
Returns the named Project associated with the ProjectRef.

Parameters:
ref - The ProjectRef instance
Returns:
The Project instance.
Throws:
SensorBaseClientException - If the server does not return the user or returns something that cannot be marshalled into Java Project instance.

getProjectSensorData

public SensorDataIndex getProjectSensorData(java.lang.String owner,
                                            java.lang.String projectName)
                                     throws SensorBaseClientException
Returns a SensorDataIndex representing all the SensorData for this Project.

Parameters:
owner - The project owner's email.
projectName - The project name.
Returns:
A SensorDataIndex.
Throws:
SensorBaseClientException - If the server does not return success or returns something that cannot be marshalled into Java SensorDataIndex instance.

getProjectSensorData

public SensorDataIndex getProjectSensorData(java.lang.String owner,
                                            java.lang.String projectName,
                                            javax.xml.datatype.XMLGregorianCalendar startTime,
                                            javax.xml.datatype.XMLGregorianCalendar endTime)
                                     throws SensorBaseClientException
Returns a SensorDataIndex representing the SensorData for the Project during the time interval.

Parameters:
owner - The project owner's email.
projectName - The project name.
startTime - The start time.
endTime - The end time.
Returns:
A SensorDataIndex.
Throws:
SensorBaseClientException - If the server does not return success or returns something that cannot be marshalled into Java SensorDataIndex instance.

getProjectSensorData

public SensorDataIndex getProjectSensorData(java.lang.String owner,
                                            java.lang.String projectName,
                                            javax.xml.datatype.XMLGregorianCalendar startTime,
                                            javax.xml.datatype.XMLGregorianCalendar endTime,
                                            java.lang.String sdt)
                                     throws SensorBaseClientException
Returns a SensorDataIndex representing the SensorData with the given SDT for the Project during the time interval.

Parameters:
owner - The project owner's email.
projectName - The project name.
startTime - The start time.
endTime - The end time.
sdt - The SensorDataType.
Returns:
A SensorDataIndex.
Throws:
SensorBaseClientException - If the server does not return success or returns something that cannot be marshalled into Java SensorDataIndex instance.

getProjectSensorData

public SensorDataIndex getProjectSensorData(java.lang.String owner,
                                            java.lang.String projectName,
                                            javax.xml.datatype.XMLGregorianCalendar startTime,
                                            javax.xml.datatype.XMLGregorianCalendar endTime,
                                            java.lang.String sdt,
                                            java.lang.String tool)
                                     throws SensorBaseClientException
Returns a SensorDataIndex representing the SensorData with the given SDT for the Project during the time interval.

Parameters:
owner - The project owner's email.
projectName - The project name.
startTime - The start time.
endTime - The end time.
sdt - The SensorDataType.
tool - The tool that generated this sensor data of the given type.
Returns:
A SensorDataIndex.
Throws:
SensorBaseClientException - If the server does not return success or returns something that cannot be marshalled into Java SensorDataIndex instance.

getProjectSensorData

public SensorDataIndex getProjectSensorData(java.lang.String owner,
                                            java.lang.String projectName,
                                            javax.xml.datatype.XMLGregorianCalendar startTime,
                                            javax.xml.datatype.XMLGregorianCalendar endTime,
                                            int startIndex,
                                            int maxInstances)
                                     throws SensorBaseClientException
Returns a SensorDataIndex representing the SensorData with the startIndex and maxInstances for the Project during the time interval. The startIndex must be non-negative, and is zero-based. The maxInstances must be non-negative. If startIndex is greater than the number of instances in the time interval, then an empty SensorDataIndex is returned.

Parameters:
owner - The project owner's email.
projectName - The project name.
startTime - The start time.
endTime - The end time.
startIndex - The zero-based index to the first Sensor Data instance to be returned in the time interval, when the instances are all ordered by timestamp.
maxInstances - The maximum number of instances to return.
Returns:
A SensorDataIndex.
Throws:
SensorBaseClientException - If the server does not return success or returns something that cannot be marshalled into Java SensorDataIndex instance.

getProjectSensorDataSnapshot

public SensorDataIndex getProjectSensorDataSnapshot(java.lang.String owner,
                                                    java.lang.String projectName,
                                                    javax.xml.datatype.XMLGregorianCalendar startTime,
                                                    javax.xml.datatype.XMLGregorianCalendar endTime,
                                                    java.lang.String sdt)
                                             throws SensorBaseClientException
Returns a SensorDataIndex containing a snapshot of the sensor data for the given project and sdt during the specified time interval. A "snapshot" is the set of sensor data with the most recent runtime value during that time interval.

Parameters:
owner - The owner of the project.
projectName - The project name.
startTime - The start time.
endTime - The end time.
sdt - The sdt of interest for the sensor data.
Returns:
The SensorDataIndex containing the "snapshot".
Throws:
SensorBaseClientException - If problems occur.

getProjectSensorDataSnapshot

public SensorDataIndex getProjectSensorDataSnapshot(java.lang.String owner,
                                                    java.lang.String projectName,
                                                    javax.xml.datatype.XMLGregorianCalendar startTime,
                                                    javax.xml.datatype.XMLGregorianCalendar endTime,
                                                    java.lang.String sdt,
                                                    java.lang.String tool)
                                             throws SensorBaseClientException
Returns a SensorDataIndex containing a snapshot of the sensor data for the given project, sdt and tool during the specified time interval. A "snapshot" is the set of sensor data with the most recent runtime value during that time interval.

Parameters:
owner - The owner of the project.
projectName - The project name.
startTime - The start time.
endTime - The end time.
sdt - The sdt of interest for the sensor data.
tool - The tool of interest for the sensor data.
Returns:
The SensorDataIndex containing the "snapshot".
Throws:
SensorBaseClientException - If problems occur.

getProjectSummary

public ProjectSummary getProjectSummary(java.lang.String owner,
                                        java.lang.String projectName,
                                        javax.xml.datatype.XMLGregorianCalendar startTime,
                                        javax.xml.datatype.XMLGregorianCalendar endTime)
                                 throws SensorBaseClientException
Returns a ProjectSummary representing a summary of the number of sensor data instances of each type for the given interval.

Parameters:
owner - The project owner.
projectName - The project name.
startTime - The start time.
endTime - The end time.
Returns:
A ProjectSummary.
Throws:
SensorBaseClientException - If problems occur.

getMultiDayProjectSummary

public MultiDayProjectSummary getMultiDayProjectSummary(java.lang.String owner,
                                                        java.lang.String projectName,
                                                        javax.xml.datatype.XMLGregorianCalendar startTime,
                                                        int numDays)
                                                 throws SensorBaseClientException
Returns a MultiDayProjectSummary for the specified interval of days.

Parameters:
owner - The project owner.
projectName - The project name.
startTime - The start day.
numDays - The number of days, each one getting a ProjectSummary instance.
Returns:
The MulitDayProjectSummary instance.
Throws:
SensorBaseClientException - If problems occur.

getMonthProjectSummary

public MultiDayProjectSummary getMonthProjectSummary(java.lang.String owner,
                                                     java.lang.String projectName,
                                                     int year,
                                                     int month)
                                              throws SensorBaseClientException
Returns a MultiDayProjectSummary for the specified project, year, and month (zero based).

Parameters:
owner - The project owner.
projectName - The project name.
year - The year.
month - The month (zero based).
Returns:
A MultiDayProjectSummary for the specified month.
Throws:
SensorBaseClientException - If problems occur.

putProject

public void putProject(Project project)
                throws SensorBaseClientException
Creates the passed Project on the server.

Parameters:
project - The project to create.
Throws:
SensorBaseClientException - If problems occur posting this data.

deleteProject

public void deleteProject(java.lang.String email,
                          java.lang.String projectName)
                   throws SensorBaseClientException
Deletes the Project given its owner and projectName.

Parameters:
email - The email of the project owner.
projectName - The project name.
Throws:
SensorBaseClientException - If the server does not indicate success.

registerUser

public static void registerUser(java.lang.String host,
                                java.lang.String email)
                         throws SensorBaseClientException
Registers the given user email with the given SensorBase. Timeout is set to 5 seconds.

Parameters:
host - The host name, such as "http://localhost:9876/sensorbase".
email - The user email.
Throws:
SensorBaseClientException - If problems occur during registration.

isHost

public static boolean isHost(java.lang.String host)
Returns true if the passed host is a SensorBase host. The timeout is set at the default timeout value. Since checking isHost() when the host is not available is expensive, we cache the timestamp whenever we find the host to be unavailable and if there is another call to isHost() within two seconds, we will immediately return false. This makes startup of clients like SensorShell go much faster, since they call isHost() several times during startup.

Parameters:
host - The URL of a sensorbase host, such as "http://localhost:9876/sensorbase".
Returns:
True if this URL responds as a SensorBase host.

isRegistered

public static boolean isRegistered(java.lang.String host,
                                   java.lang.String email,
                                   java.lang.String password)
Returns true if the user and password is registered as a user with this host.

Parameters:
host - The URL of a sensorbase host, such as "http://localhost:9876/sensorbase".
email - The user email.
password - The user password.
Returns:
True if this user is registered with this host.

enableCaching

public void enableCaching(java.lang.String cacheName,
                          java.lang.String subDir,
                          java.lang.Double maxLife,
                          java.lang.Long capacity)
Enables caching in this client. If caching has already been enabled, then does nothing.

Parameters:
cacheName - The name of the cache.
subDir - The subdirectory in which the cache backend store is saved.
maxLife - The default expiration time for objects, in days.
capacity - The maximum number of instances to be held in-memory.

clearCache

public void clearCache()
Delete all entries from this cache. If the cache is not enabled, then does nothing.


compressTables

public void compressTables()
                    throws SensorBaseClientException
Compresses the server database tables. You must be the admin user in order for this command to succeed.

Throws:
SensorBaseClientException - If problems occur posting this data.

indexTables

public void indexTables()
                 throws SensorBaseClientException
Indexes the server database tables. You must be the admin user in order for this command to succeed.

Throws:
SensorBaseClientException - If problems occur posting this data.

rowCount

public int rowCount(java.lang.String table)
             throws SensorBaseClientException
Gets the rowcount for the specified table. You must be the admin user in order for this command to succeed.

Parameters:
table - The name of the table whose rowcount is to be retrieved.
Returns:
The number of rows in that table.
Throws:
SensorBaseClientException - If problems occur posting this data. This can happen if the user is not the admin user, or if the table name is invalid.