org.gcube.common.core.resources
Class GCUBEResource

java.lang.Object
  extended by org.gcube.common.core.resources.GCUBEResource
Direct Known Subclasses:
GCUBECollection, GCUBECS, GCUBECSInstance, GCUBEExternalRunningInstance, GCUBEGenericResource, GCUBEHostingNode, GCUBEMCollection, GCUBERunningInstance, GCUBERuntimeResource, GCUBEService

public abstract class GCUBEResource
extends Object

Specifies the behaviour common to all gCUBE resources.

Author:
Andrea Manzi (CNR), Fabio Simeoni (University of Strathclyde)

Nested Class Summary
 class GCUBEResource.AddScopeEvent
          Generic GCUBEEvent for the addition of a scope to the resource.
static class GCUBEResource.InvalidScopeException
          NoValidScopeFoundException exception
 class GCUBEResource.RemoveScopeEvent
          Generic GCUBEEvent for the removal of a scope from the resource.
static class GCUBEResource.ResourceConsumer
          Base implementation of a GCUBEConsumer of ResourceEvents.
 class GCUBEResource.ResourceEvent<PAYLOAD>
          Single GCUBEEvent type for GHNTopics.
static class GCUBEResource.ResourceTopic
          A GCUBETopic for lifetime events .
 
Field Summary
protected  GCUBEProducer<GCUBEResource.ResourceTopic,Object> eventProducer
          Internal GCUBEProducer for ResourceEvents.
protected  GCUBELog logger
          The object logger;
protected  String resourceVersion
          The version of the Profile to which this resource is compliant to.
protected  String type
          The resource type.
 
Constructor Summary
GCUBEResource()
           
 
Method Summary
 Set<GCUBEScope> addScope(GCUBEScope... scopes)
          Adds one or more scopes from the resource.
 boolean equals(Object obj)
           
 String getID()
          Returns the resource identifier.
 String getLastResourceVersion()
           
 String getResourceVersion()
           
 Map<String,GCUBEScope> getScopes()
          Returns a read-only map of the scopes associated with the resource index by scope expression.
 String getType()
          Returns the type of the resource.
 boolean inScope(GCUBEScope... scopes)
          Indicates whether the resource is in one or more given scopes.
abstract  void load(Reader reader)
          Deserialise the state of the resource from an existing serialisation.
 Set<GCUBEScope> removeScope(GCUBEScope... scopes)
          Removes one or more scopes from the resource.
 boolean setID(String id)
          Sets the resource identifier.
 void setLogger(GCUBELog logger)
          Sets the resource's logger.
 void setResourceVersion(String version)
           
abstract  void store(Writer writer)
          Serialise the current state of the resource.
 void subscribeResourceEvents(GCUBEResource.ResourceConsumer consumer, GCUBEResource.ResourceTopic... topics)
          Subscribes a consumer to one or more ResourceEvents.
 Set<GCUBEScope> validateAddScopes(GCUBEScope... scopes)
          Invoked by addScope(GCUBEScope...), to filter scopes as per resource-specific scoping rules.By default, it returns its input.
 Set<GCUBEScope> validateRemoveScopes(GCUBEScope... scopes)
          Invoked by removeScope(GCUBEScope...), to filter scopes as per resource-specific scoping rules.By default, it returns its input.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected GCUBELog logger
The object logger;


type

protected String type
The resource type.


resourceVersion

protected String resourceVersion
The version of the Profile to which this resource is compliant to.


eventProducer

protected GCUBEProducer<GCUBEResource.ResourceTopic,Object> eventProducer
Internal GCUBEProducer for ResourceEvents.

Constructor Detail

GCUBEResource

public GCUBEResource()
Method Detail

setLogger

public void setLogger(GCUBELog logger)
Sets the resource's logger.

Parameters:
logger - the logger.

getType

public String getType()
Returns the type of the resource.

Returns:
the type.

getID

public String getID()
Returns the resource identifier.

Returns:
the identifier.

setID

public boolean setID(String id)
Sets the resource identifier. As the identifier is a one-time constant, the operation returns successfully from the first invocation only.

Parameters:
id - the identifier
Returns:
true if the identifier was set, false otherwise.

getScopes

public Map<String,GCUBEScope> getScopes()
Returns a read-only map of the scopes associated with the resource index by scope expression.

Returns:
the map.

addScope

public Set<GCUBEScope> addScope(GCUBEScope... scopes)
Adds one or more scopes from the resource.

Parameters:
scopes - the scopes.

validateAddScopes

public Set<GCUBEScope> validateAddScopes(GCUBEScope... scopes)
Invoked by addScope(GCUBEScope...), to filter scopes as per resource-specific scoping rules.By default, it returns its input.

Parameters:
scopes - the scopes.
Returns:
the subset of valid scopes.

removeScope

public Set<GCUBEScope> removeScope(GCUBEScope... scopes)
Removes one or more scopes from the resource. Only scopes currently associated with the resource are actually removed.

Parameters:
scopes - the scopes.
Returns:
the list of scopes removed from the resource, empty if no scope was actually removed.

validateRemoveScopes

public Set<GCUBEScope> validateRemoveScopes(GCUBEScope... scopes)
Invoked by removeScope(GCUBEScope...), to filter scopes as per resource-specific scoping rules.By default, it returns its input.

Parameters:
scopes - the scopes.
Returns:
the subset of valid scopes.

inScope

public boolean inScope(GCUBEScope... scopes)
Indicates whether the resource is in one or more given scopes.

Parameters:
scopes - the scopes.
Returns:
true if it is in all the input scopes, false otherwise.

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

load

public abstract void load(Reader reader)
                   throws Exception
Deserialise the state of the resource from an existing serialisation. The operations is destructive with respect to the current state of the resource.

Parameters:
reader - the Reader which exposes the serialisation.
Throws:
UnsupportedOperationException - if this operation is not supported by implementation.
Exception - if the operation is supported but could not complete successfully.

store

public abstract void store(Writer writer)
                    throws Exception
Serialise the current state of the resource.

Parameters:
writer - the Writer which exposes the serialisation.
Throws:
UnsupportedOperationException
UnsupportedOperationException - if this operation is not supported by implementation.
Exception - if the operation is supported but could not complete successfully.

subscribeResourceEvents

public void subscribeResourceEvents(GCUBEResource.ResourceConsumer consumer,
                                    GCUBEResource.ResourceTopic... topics)
                             throws Exception
Subscribes a consumer to one or more ResourceEvents.

Parameters:
consumer - the consumer.
topics - the topics of interest.
Throws:
Exception - if the subscription could not be completed.

getResourceVersion

public String getResourceVersion()
Returns:
the resource version

setResourceVersion

public void setResourceVersion(String version)
Parameters:
version - the resource version to set

getLastResourceVersion

public String getLastResourceVersion()
Returns:
the last version available of the resource


Copyright © 2012. All Rights Reserved.