P-Grid v2.0a2 API Specification

p2p.storage
Interface TypeHandler


public interface TypeHandler

Used to define types of data items to store. No particular operations are defined; however, implementers are encouraged to provide consistent implementations of java.land.Object methods, including equals and hashCode, so that different types can be distinguished.

Version:
1.0.0
Author:
@author Roman Schmidt

Method Summary
 DataItem createDataItem()
          Create a DataItem instance compatible with the Storage implementation.
 DataItem createDataItem(GUID guid, Key key, Peer host, Object data)
          Create a DataItem instance compatible with the Storage implementation.
 DataItem createDataItem(Object data)
          Create a DataItem instance compatible with the Storage implementation.
 Key generateKey(Object obj)
          Generate a Key instance compatible with the P2P implementation.
 KeyRange generateKeyRange(Object lowerBound, Object higherBound)
          Generate a KeyRange instance compatible with the P2P implementation.
 void handleLocalSearch(Query query, SearchListener listener)
          Searches localy for all dataitems matching the query query
 String submitSearchHigherBoundValue(Query query)
          Construct the string out of the higherbound that will be use to query the network.
 String submitSearchLowerBoundValue(Query query)
          Construct the string out of the lowerbound that will be use to query the network.
 

Method Detail

createDataItem

DataItem createDataItem()
Create a DataItem instance compatible with the Storage implementation.

Returns:
a DataItem instance

createDataItem

DataItem createDataItem(Object data)
Create a DataItem instance compatible with the Storage implementation.

Parameters:
data - the encapsulated data
Returns:
a DataItem instance

createDataItem

DataItem createDataItem(GUID guid,
                        Key key,
                        Peer host,
                        Object data)
Create a DataItem instance compatible with the Storage implementation.

Parameters:
guid - the guid of the data.
key - the key generated of the data.
host - the host.
data - the encapsulated data.
Returns:
a DataItem instance

handleLocalSearch

void handleLocalSearch(Query query,
                       SearchListener listener)
Searches localy for all dataitems matching the query query

Parameters:
query - the query.
listener - the search listener.

submitSearchLowerBoundValue

String submitSearchLowerBoundValue(Query query)
Construct the string out of the lowerbound that will be use to query the network.
For exemple, if you have a lowerbound equals to "Key=Value" you could return "ValueKey" as the effective search string. The lower bound will be inlcuded in the query, but the lower bound used for the searching will be the return value of this method.

If you want to search with the lower bound, either return null or the lower bound

Parameters:
query - the query being processed.
Returns:
a string use to perform the search

submitSearchHigherBoundValue

String submitSearchHigherBoundValue(Query query)
Construct the string out of the higherbound that will be use to query the network.
For exemple, if you have a higherbound equals to "Key=Value" you could return "ValueKey" as the effective search string. The higher bound will be inlcuded in the query, but the higher bound used for the searching will be the return value of this method.

If you want to search with the higher bound, either return null or the lower bound

Parameters:
query - the query being processed.
Returns:
a string use to perform the search

generateKey

Key generateKey(Object obj)
Generate a Key instance compatible with the P2P implementation. Acceptable source object types depend on implementation. When working with the storage layer, only this method should be called to generate a key, not the one found in the basic interface.

Parameters:
obj - the source object from which to generate the key
Returns:
the generated Key implementation

generateKeyRange

KeyRange generateKeyRange(Object lowerBound,
                          Object higherBound)
Generate a KeyRange instance compatible with the P2P implementation. Acceptable source object types depend on implementation. When working with the storage layer, only this method should be called to generate a key, not the one found in the basic interface.

Parameters:
lowerBound - the source object from which to generate the lower key
lowerBound - the source object from which to generate the higher key
Returns:
the generated Key implementation

P-Grid v2.0a2 API Specification

This is open source software distributed under the terms of the GNU General Public License, a copy of which is included in the file LICENSE. If not you can find the GPL at http://www.gnu.org/copyleft/gpl.txt