jxtaimpl.storage
Class CmsStorage

java.lang.Object
  |
  +--jxtaimpl.storage.CmsStorage
All Implemented Interfaces:
Clearable, GenericStorage, QueryStorage, ResourceManager, Storage

public class CmsStorage
extends Object
implements QueryStorage, ResourceManager

This class is in charge of managing the resources to be shared within the Anthill network.

Author:
Francesco Russo (frusso@cs.unibo.it)

Field Summary
 
Fields inherited from interface anthill.storage.Storage
DOC_STORAGE, PHR_STORAGE, URL_STORAGE
 
Constructor Summary
CmsStorage(String species, long size, String confDir, URL pipeId, String pipeName, String pipeType)
          This is the constructor.
 
Method Summary
 void addResource(Object key, Resource resource)
          Deprecated. The public void addResource(Object key, Resource resource, byte[] buffer) method should be used in place of this one
 void addResource(Object key, Resource resource, byte[] buffer)
          Adds the resource described by Resource resource and contained in byte[] buffer.
 void clear()
          This method does nothing, it has no sense in the jxtaimpl implementation.
 boolean containsResource(Object key)
          Returns true if one resource satisfing the query key, (please see Query javadocs) is contained in the storage, false otherwise.
 Resource[] getAllResources()
          This method will return the complete set of resources stored in the local nest if the storage is not empty, else it returns null.
 long getCapacity()
          Returns the initial capacity of this generic storage.
 InputStream getInputStreamForContent(byte[] contentId)
          Gets the InputStream for reading in the resource identified by the the given contentId.
 long getRemainingCapacity()
          Returns the remaining capacity of this generic storage.
 Resource getResource(Object key)
          Returns the first resource which satisfies the query (key).
 Resource[] getResources(Object key)
          Returns the resources associated with the specified key.
 Iterator iterator()
          Returns the complete set of resources stored in this storage object using an iterator.
 void removeResource(Object query)
          This method removes the first resource which satisfies the given query.
 void share(byte[] content, String name, String type, String description)
          This method is used by the Nest instance in order to share new resources not found by ants, but passed by the application level.
 void share(File file, String name, String type, String description)
          This method is used by the Nest instance in order to share new resources not found by ants, but passed by the application level.
 void unShare(AnthillResource resource)
          This method removes the specified resouce from the local storage.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CmsStorage

public CmsStorage(String species,
                  long size,
                  String confDir,
                  URL pipeId,
                  String pipeName,
                  String pipeType)
This is the constructor. The "species" parameter is the invoking ant's species. Once invoked it will create in the user's home directory a new folder called AnthillResources, which will be used for storing information about the resources to be shared with all the other nests.

Parameters:
species - The ant species this storage is associated to
size - The desired storage's size expressed in bytes
pipeId - This is the JXTA pipeID of the local jxtaimpl.DownloadService input-pipe waiting for download requests to come
pipeName - The pipe's logical name
pipeType - The pipe's type (point-to-point, propagate, secure)
Method Detail

clear

public void clear()
This method does nothing, it has no sense in the jxtaimpl implementation.

Specified by:
clear in interface Clearable

getResource

public Resource getResource(Object key)
Returns the first resource which satisfies the query (key). If the key is not associated with any resource, a null value is returned. In the jxtaimpl implementation of Anthill, the key object has to be an instance of the the class Query belonging to this same package.

Specified by:
getResource in interface GenericStorage
Parameters:
key - whose associated resource to retreive.
Returns:
resource with which the specified key is associated.

getResources

public Resource[] getResources(Object key)
Returns the resources associated with the specified key. If the key is not associated with any resource, a null value is returned. In the jxtaimpl implementation of Anthill, the key object has to be an instance of the the class Query belonging to this same package.

Specified by:
getResources in interface QueryStorage
Parameters:
key - whose associated resource to retreive.
Returns:
resource with which the specified key is associated.

getAllResources

public Resource[] getAllResources()
This method will return the complete set of resources stored in the local nest if the storage is not empty, else it returns null.


containsResource

public boolean containsResource(Object key)
Returns true if one resource satisfing the query key, (please see Query javadocs) is contained in the storage, false otherwise. The key is meant to be a couple like this: (elementName, values). Both of them are meant to be String. All the interesting values contained in values must be separated by a blank space. It doesn't matter whether they are upper-case or not.

Specified by:
containsResource in interface GenericStorage
Parameters:
key - the key to be searched
Returns:
true if the resource associated to key is contained in the storage

addResource

public void addResource(Object key,
                        Resource resource)
                 throws CapacityException
Deprecated. The public void addResource(Object key, Resource resource, byte[] buffer) method should be used in place of this one

Adds a resource to the storage and associates it to the specified key if and only if the same resource is not already locally stored. If the remaining capacity of the storage is not sufficient to store the resource, a CapacityException is thrown containing information about the remaining capacity. Method getContentLength() may be invoked on the resource to determine the amount of space required by the resource. In order to be stored on persistent storage, resource must implement the Serializable interface.

Specified by:
addResource in interface GenericStorage
Parameters:
key - the key identifying the resource
resource - the resource to be added
Throws:
CapacityException - raised if the given resource object exceeds the total available capacity for this storage.

addResource

public void addResource(Object key,
                        Resource resource,
                        byte[] buffer)
                 throws CapacityException
Adds the resource described by Resource resource and contained in byte[] buffer. This method should be invoked in place of the addResource(Object key, Resource resource) method for locally adding a new resource.

Parameters:
key - The key identifieing the resource. This might be null since in this method's signature there is a resource descriptor as well
resource - This is the resource descriptor which has to be an AnthillResource instance
buffer - This is the content which has to be locally stored
Throws:
CapacityException

removeResource

public void removeResource(Object query)
This method removes the first resource which satisfies the given query.

Specified by:
removeResource in interface GenericStorage
Parameters:
query - This object must be a jxtaimpl.storage.Query instance or has to extend it for this method to work. It contains the couple (ElementName, Value) identifieing the resource we want to remove

share

public void share(File file,
                  String name,
                  String type,
                  String description)
           throws ResourceAlreadyStoredException,
                  CapacityException
This method is used by the Nest instance in order to share new resources not found by ants, but passed by the application level. With this method the resource will not be copied to the folder in charge of storing all the contents to be shared.

Parameters:
file - The file representing the resource we want to share
name - The logical name for the resource
type - The resource's type
description - A logical description of the resource
ResourceAlreadyStoredException
CapacityException

share

public void share(byte[] content,
                  String name,
                  String type,
                  String description)
           throws ResourceAlreadyStoredException,
                  CapacityException
This method is used by the Nest instance in order to share new resources not found by ants, but passed by the application level. With this method the resource will not be copied to the folder in charge of storing all the contents to be shared.

Parameters:
name - The logical name for the resource
type - The resource's type
description - A logical description of the resource
ResourceAlreadyStoredException
CapacityException

unShare

public void unShare(AnthillResource resource)
This method removes the specified resouce from the local storage.


iterator

public Iterator iterator()
Returns the complete set of resources stored in this storage object using an iterator.

Specified by:
iterator in interface GenericStorage
Returns:
iterator representing this storage object, allowing to inspect its content.

getCapacity

public long getCapacity()
Returns the initial capacity of this generic storage.

Specified by:
getCapacity in interface GenericStorage

getRemainingCapacity

public long getRemainingCapacity()
Returns the remaining capacity of this generic storage.

Specified by:
getRemainingCapacity in interface GenericStorage

getInputStreamForContent

public InputStream getInputStreamForContent(byte[] contentId)
Gets the InputStream for reading in the resource identified by the the given contentId. The byte array is actually the String rapresentation of the ContentIdImpl instance. This method should only be used by the Nest instance in order to upload the resource identified by the given contentID.

Parameters:
contentId - The byte array representing the String from which the ContentIdImpl identifieing the resource we are interested in should be generated