org.javaswift.joss.client.core
Class AbstractAccount

java.lang.Object
  extended by org.javaswift.joss.client.core.AbstractObjectStoreEntity<AccountInformation>
      extended by org.javaswift.joss.client.core.AbstractAccount
All Implemented Interfaces:
Account, ListHolder<Container>, ObjectStoreEntity
Direct Known Subclasses:
AccountImpl, AccountMock

public abstract class AbstractAccount
extends AbstractObjectStoreEntity<AccountInformation>
implements Account


Field Summary
static org.slf4j.Logger LOG
           
 
Fields inherited from class org.javaswift.joss.client.core.AbstractObjectStoreEntity
ALLOW_CACHING, info, staleHeaders
 
Constructor Summary
AbstractAccount(AccountCommandFactory commandFactory, ContainerFactory<Container> containerFactory, ContainerFactory<Website> websiteFactory, boolean allowCaching)
           
 
Method Summary
 Access authenticate()
          Trigger the authentication against Object Store.
protected  Metadata createMetadataEntry(String name, String value)
           
 long getActualServerTimeInSeconds(long seconds)
          Calculate the server time taking into account the number of seconds passed.
 long getBytesUsed()
          The number of bytes stored by the StoredObjects in all Containers in the Account.
 Container getContainer(String containerName)
          Returns a handle for a container.
 int getCount()
          The number of child entities (ListSubjects) that are being held by the ListHolder
 AccountCommandFactory getFactory()
           
 String getHashPassword()
          Returns the hash password originally set on Account.
protected  void getInfo(boolean allowErrorLog)
           
 int getMaxPageSize()
          The ObjectStore server will force a maximum page size.
 int getNumberOfCalls()
          Returns the number of HTTP calls that have been made to the ObjectStore server.
 int getObjectCount()
          The number of StoredObjects in all Containers in the Account.
 String getOriginalHost()
          Returns the original host, regardless of the configured public and private host settings
 PaginationMap getPaginationMap(int pageSize)
          Returns a PaginationMap of a listing of Containers.
 PaginationMap getPaginationMap(String prefix, int pageSize)
          Returns a PaginationMap of a listing of Containers.
 String getPathForEntity()
           
 String getPrivateURL()
          Returns the private URL which is used for the underlying stored objects
 String getPublicURL()
          Returns the public URL which is used for the underlying stored objects
 long getServerTime()
          Returns the server time in milliseconds since 1970
 Tenants getTenants()
          Returns the tenants of the account.
 Website getWebsite(String containerName)
          Returns a handle for a website.
 void increaseCallCounter()
          Increase the call counter which tracks how many calls are made to the ObjectStore
 boolean isAllowReauthenticate()
          Whether reauthentication on expiration of the authentication token is allowed, or this is done manually by the client
 boolean isTenantSupplied()
          Checks whether a tenant ID and/or name were supplied.
 Collection<Container> list()
          Returns all the containers in an Account.
 Collection<Container> list(PaginationMap paginationMap, int page)
          Returns a number equal to pageSize of Container elements, starting with the first element after the Container named the same as marker.
 Collection<Container> list(String prefix, String marker, int pageSize)
          Returns a number equal to pageSize of Container elements, starting with the first element after the Container named the same as marker.
 void resetContainerCache()
          Empties the Container Cache
protected  void saveSpecificMetadata()
           
 AbstractAccount setAllowContainerCaching(boolean allowContainerCaching)
          If ContainerCaching is enabled, Account will keep track of its Container instances and reuse them.
 AbstractAccount setAllowReauthenticate(boolean allowReauthenticate)
          An ObjectStore authentication token will expire after 24 hours.
 AbstractAccount setHashPassword(String hashPassword)
          Saves the password to the Account.
 AbstractAccount setPrivateHost(String privateHost)
          Set your own private host to prefix the public URLs of objects
 AbstractAccount setPublicHost(String publicHost)
          Set your own public host to prefix the public URLs of objects
 void synchronizeWithServerTime()
          Compares the local time to the server time and maintains a number of milliseconds to account for the difference.
 
Methods inherited from class org.javaswift.joss.client.core.AbstractObjectStoreEntity
checkForInfo, checkForInfo, checkForInfoAndAllowHeaderSet, checkForInfoDisallowErrorLog, exists, getMetadata, getMetadata, getPath, invalidate, isAllowCaching, isInfoRetrieved, isStale, reload, removeAndDoNotSaveMetadata, removeAndSaveMetadata, saveMetadata, setAndDoNotSaveMetadata, setAndSaveMetadata, setInfoRetrieved, setMetadata
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.javaswift.joss.model.Account
reload
 
Methods inherited from interface org.javaswift.joss.model.ObjectStoreEntity
getMetadata, getMetadata, getPath, removeAndDoNotSaveMetadata, removeAndSaveMetadata, saveMetadata, setAndDoNotSaveMetadata, setAndSaveMetadata, setMetadata
 

Field Detail

LOG

public static final org.slf4j.Logger LOG
Constructor Detail

AbstractAccount

public AbstractAccount(AccountCommandFactory commandFactory,
                       ContainerFactory<Container> containerFactory,
                       ContainerFactory<Website> websiteFactory,
                       boolean allowCaching)
Method Detail

list

public Collection<Container> list()
Description copied from interface: ListHolder
Returns all the containers in an Account. Note that this method returns a maxmimum of 9,999 Containers and no more (see http://docs.openstack.org/api/openstack-object-storage/1.0/content/list-objects.html)

Specified by:
list in interface ListHolder<Container>
Returns:
the containers in an Account

list

public Collection<Container> list(PaginationMap paginationMap,
                                  int page)
Description copied from interface: ListHolder
Returns a number equal to pageSize of Container elements, starting with the first element after the Container named the same as marker.

Specified by:
list in interface ListHolder<Container>
Parameters:
paginationMap - the map that is fetched with getPaginationMap and maps from page to marker
page - the page to return the Containers for
Returns:
page of Containers in an Account with a total of pageSize elements

list

public Collection<Container> list(String prefix,
                                  String marker,
                                  int pageSize)
Description copied from interface: ListHolder
Returns a number equal to pageSize of Container elements, starting with the first element after the Container named the same as marker.

Specified by:
list in interface ListHolder<Container>
marker - the last element on the previous page
pageSize - the number of elements to return
Returns:
page of Containers in an Account with a total of pageSize elements

getPaginationMap

public PaginationMap getPaginationMap(String prefix,
                                      int pageSize)
Description copied from interface: ListHolder
Returns a PaginationMap of a listing of Containers. The map can be used to supply the OpenStack API with a marker (ie, last record on the previous page) and a limit (ie, page size). BE AWARE: this method iterates over ALL Container names to draw up the map, therefore it must be considered an expensive call.

Specified by:
getPaginationMap in interface ListHolder<Container>
Parameters:
prefix - the names must start with the prefix or else will be filtered out
pageSize - number of elements on a single page
Returns:
the pagination map for all the Container elements in Account

getPaginationMap

public PaginationMap getPaginationMap(int pageSize)
Description copied from interface: ListHolder
Returns a PaginationMap of a listing of Containers. The map can be used to supply the OpenStack API with a marker (ie, last record on the previous page) and a limit (ie, page size). BE AWARE: this method iterates over ALL Container names to draw up the map, therefore it must be considered an expensive call.

Specified by:
getPaginationMap in interface ListHolder<Container>
Parameters:
pageSize - number of elements on a single page
Returns:
the pagination map for all the Container elements in Account

getHashPassword

public String getHashPassword()
Description copied from interface: Account
Returns the hash password originally set on Account.

Specified by:
getHashPassword in interface Account
Returns:
hash password

setHashPassword

public AbstractAccount setHashPassword(String hashPassword)
Description copied from interface: Account
Saves the password to the Account. The password will be used to create server side hashes. This is required for TempURL (both GET and PUT). The server will match a generated hash against the hash that is passed in a tempURL. If identical, it passed the first test. Note that if password is not set, TempURLs will not work. Note that the password saved is the one set either in AccountConfig, or set with Account.setHashPassword(String).

Specified by:
setHashPassword in interface Account
Parameters:
hashPassword - the password to use for generating the hashes

setPublicHost

public AbstractAccount setPublicHost(String publicHost)
Description copied from interface: Account
Set your own public host to prefix the public URLs of objects

Specified by:
setPublicHost in interface Account
Parameters:
publicHost - host of an object's public URL
Returns:
instance of Account

setPrivateHost

public AbstractAccount setPrivateHost(String privateHost)
Description copied from interface: Account
Set your own private host to prefix the public URLs of objects

Specified by:
setPrivateHost in interface Account
Parameters:
privateHost - host of an object's private URL
Returns:
instance of Account

setAllowReauthenticate

public AbstractAccount setAllowReauthenticate(boolean allowReauthenticate)
Description copied from interface: Account
An ObjectStore authentication token will expire after 24 hours. In a long-living web application, the account instance may exist longer than that. If reauthentication is allowed, a new token will be fetched once the existing one has expired.

Specified by:
setAllowReauthenticate in interface Account
Parameters:
allowReauthenticate - whether reauthentication is allowed
Returns:
instance of Account

setAllowContainerCaching

public AbstractAccount setAllowContainerCaching(boolean allowContainerCaching)
Description copied from interface: Account
If ContainerCaching is enabled, Account will keep track of its Container instances and reuse them.

Specified by:
setAllowContainerCaching in interface Account
Parameters:
allowContainerCaching - whether container caching is allowed

isAllowReauthenticate

public boolean isAllowReauthenticate()
Description copied from interface: Account
Whether reauthentication on expiration of the authentication token is allowed, or this is done manually by the client

Specified by:
isAllowReauthenticate in interface Account
Returns:
whether reauthentication is allowed

getCount

public int getCount()
Description copied from interface: ListHolder
The number of child entities (ListSubjects) that are being held by the ListHolder

Specified by:
getCount in interface ListHolder<Container>
Returns:
number of child entities

getBytesUsed

public long getBytesUsed()
Description copied from interface: Account
The number of bytes stored by the StoredObjects in all Containers in the Account.

Specified by:
getBytesUsed in interface Account
Returns:
number of bytes

getObjectCount

public int getObjectCount()
Description copied from interface: Account
The number of StoredObjects in all Containers in the Account.

Specified by:
getObjectCount in interface Account
Returns:
number of StoredObjects

getServerTime

public long getServerTime()
Description copied from interface: Account
Returns the server time in milliseconds since 1970

Specified by:
getServerTime in interface Account
Returns:
server time

getActualServerTimeInSeconds

public long getActualServerTimeInSeconds(long seconds)
Description copied from interface: Account
Calculate the server time taking into account the number of seconds passed. This method makes use of the server time modifier which is calculated in synchronizeWithServerTime().

Specified by:
getActualServerTimeInSeconds in interface Account
Parameters:
seconds - number of seconds after the actual server time
Returns:
calculated server time, including the number of seconds in the future

synchronizeWithServerTime

public void synchronizeWithServerTime()
Description copied from interface: Account
Compares the local time to the server time and maintains a number of milliseconds to account for the difference. This number is taken into account when an absolute expiry time is passed to the server.

Specified by:
synchronizeWithServerTime in interface Account

createMetadataEntry

protected Metadata createMetadataEntry(String name,
                                       String value)
Specified by:
createMetadataEntry in class AbstractObjectStoreEntity<AccountInformation>

getMaxPageSize

public int getMaxPageSize()
Description copied from interface: ListHolder
The ObjectStore server will force a maximum page size. This value helps to determine blocks that must be read, which is used internally for setting up a pagination map.

Specified by:
getMaxPageSize in interface ListHolder<Container>
Returns:
maximum page size for the child entity

increaseCallCounter

public void increaseCallCounter()
Description copied from interface: Account
Increase the call counter which tracks how many calls are made to the ObjectStore

Specified by:
increaseCallCounter in interface Account

getNumberOfCalls

public int getNumberOfCalls()
Description copied from interface: Account
Returns the number of HTTP calls that have been made to the ObjectStore server. This could be useful to check the efficiency of the methods and configuration in use

Specified by:
getNumberOfCalls in interface Account
Returns:
number of calls made to the ObjectStore server

getFactory

public AccountCommandFactory getFactory()

authenticate

public Access authenticate()
Description copied from interface: Account
Trigger the authentication against Object Store. There are two use cases for this method. The first is triggered pro-actively by the user by calling authenticate on the client. The second is when the token has expired and AbstractSecureCommand triggers a re-authentication.

Specified by:
authenticate in interface Account
Returns:
the access element including a new token

getPublicURL

public String getPublicURL()
Description copied from interface: Account
Returns the public URL which is used for the underlying stored objects

Specified by:
getPublicURL in interface Account
Returns:
the public URL of the underlying stored objects

getPrivateURL

public String getPrivateURL()
Description copied from interface: Account
Returns the private URL which is used for the underlying stored objects

Specified by:
getPrivateURL in interface Account
Returns:
the private URL of the underlying stored objects

saveSpecificMetadata

protected void saveSpecificMetadata()
Specified by:
saveSpecificMetadata in class AbstractObjectStoreEntity<AccountInformation>

getInfo

protected void getInfo(boolean allowErrorLog)
Specified by:
getInfo in class AbstractObjectStoreEntity<AccountInformation>

getTenants

public Tenants getTenants()
Description copied from interface: Account
Returns the tenants of the account. Note that this is the only Account method that interacts with the object store and will work when no tenant has been set. All others will throw an exception.

Specified by:
getTenants in interface Account
Returns:
the tenants belonging to the Account

isTenantSupplied

public boolean isTenantSupplied()
Description copied from interface: Account
Checks whether a tenant ID and/or name were supplied. If not, the account can only be used to retrieve a list of tenants.

Specified by:
isTenantSupplied in interface Account

getPathForEntity

public String getPathForEntity()
                        throws UnsupportedEncodingException
Specified by:
getPathForEntity in class AbstractObjectStoreEntity<AccountInformation>
Throws:
UnsupportedEncodingException

getContainer

public Container getContainer(String containerName)
Description copied from interface: Account
Returns a handle for a container. Note that this method DOES NOT create a container in the Object Store or otherwise place a call to the Object Store

Specified by:
getContainer in interface Account
Parameters:
containerName - name of the container to create a handle for
Returns:
the container handle

getWebsite

public Website getWebsite(String containerName)
Description copied from interface: Account
Returns a handle for a website. Note that this method DOES NOT create a website in the Object Store or otherwise place a call to the Object Store

Specified by:
getWebsite in interface Account
Parameters:
containerName - name of the website to create a handle for
Returns:
the website handle

resetContainerCache

public void resetContainerCache()
Description copied from interface: Account
Empties the Container Cache

Specified by:
resetContainerCache in interface Account

getOriginalHost

public String getOriginalHost()
Description copied from interface: Account
Returns the original host, regardless of the configured public and private host settings

Specified by:
getOriginalHost in interface Account
Returns:
original public host


Copyright © 2012-2014 42 BV. All Rights Reserved.