2 * Copyright 2001-2007 Internet2
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * @file xmltooling/util/StorageService.h
20 * Generic data storage interface
23 #ifndef __xmltooling_storage_h__
24 #define __xmltooling_storage_h__
26 #include <xmltooling/XMLObject.h>
30 namespace xmltooling {
33 * Generic data storage facility for use by services that require
34 * some degree of persistence. Implementations will vary in how much
35 * persistence they can supply.
37 * <p>Storage is divided into "contexts" identified by a string label.
38 * Keys need to be unique only within a given context, so multiple
39 * components can share a single storage service safely as long as they
40 * use different labels.
42 class XMLTOOL_API StorageService
44 MAKE_NONCOPYABLE(StorageService);
46 virtual ~StorageService() {}
49 * Creates a new "short" record in the storage service.
51 * @param context a storage context label
52 * @param key null-terminated unique key of up to 255 bytes
53 * @param value null-terminated value of up to 255 bytes to store
54 * @param expiration an expiration timestamp, after which the record can be purged
56 * @throws IOException raised if errors occur in the insertion process
58 virtual void createString(const char* context, const char* key, const char* value, time_t expiration)=0;
61 * Returns an existing "short" record from the storage service.
63 * <p>The version parameter can be set for "If-Modified-Since" semantics.
65 * @param context a storage context label
66 * @param key null-terminated unique key of up to 255 bytes
67 * @param pvalue location in which to return the record value
68 * @param pexpiration location in which to return the expiration timestamp
69 * @param version if > 0, only copy back data if newer than supplied version
70 * @return the version of the record read back, or 0 if no record exists
72 * @throws IOException raised if errors occur in the read process
74 virtual int readString(
75 const char* context, const char* key, std::string* pvalue=NULL, time_t* pexpiration=NULL, int version=0
79 * Updates an existing "short" record in the storage service.
81 * @param context a storage context label
82 * @param key null-terminated unique key of up to 255 bytes
83 * @param value null-terminated value of up to 255 bytes to store, or NULL to leave alone
84 * @param expiration a new expiration timestamp, or 0 to leave alone
85 * @param version if > 0, only update if the current version matches this value
86 * @return the version of the record after update, 0 if no record exists, or -1 if the version
87 * parameter is non-zero and does not match the current version before update (so the caller is out of sync)
89 * @throws IOException raised if errors occur in the update process
91 virtual int updateString(
92 const char* context, const char* key, const char* value=NULL, time_t expiration=0, int version=0
96 * Deletes an existing "short" record from the storage service.
98 * @param context a storage context label
99 * @param key null-terminated unique key of up to 255 bytes
100 * @return true iff the record existed and was deleted
102 * @throws IOException raised if errors occur in the deletion process
104 virtual bool deleteString(const char* context, const char* key)=0;
107 * Creates a new "long" record in the storage service.
109 * @param context a storage context label
110 * @param key null-terminated unique key of up to 255 bytes
111 * @param value null-terminated value of arbitrary length
112 * @param expiration an expiration timestamp, after which the record can be purged
114 * @throws IOException raised if errors occur in the insertion process
116 virtual void createText(const char* context, const char* key, const char* value, time_t expiration)=0;
119 * Returns an existing "long" record from the storage service.
121 * <p>The version parameter can be set for "If-Modified-Since" semantics.
123 * @param context a storage context label
124 * @param key null-terminated unique key of up to 255 bytes
125 * @param pvalue location in which to return the record value
126 * @param pexpiration location in which to return the expiration timestamp
127 * @param version if > 0, only copy back data if newer than supplied version
128 * @return the version of the record read back, or 0 if no record exists
130 * @throws IOException raised if errors occur in the read process
132 virtual int readText(
133 const char* context, const char* key, std::string* pvalue=NULL, time_t* pexpiration=NULL, int version=0
137 * Updates an existing "long" record in the storage service.
139 * @param context a storage context label
140 * @param key null-terminated unique key of up to 255 bytes
141 * @param value null-terminated value of arbitrary length to store, or NULL to leave alone
142 * @param expiration a new expiration timestamp, or 0 to leave alone
143 * @param version if > 0, only update if the current version matches this value
144 * @return the version of the record after update, 0 if no record exists, or -1 if the version
145 * parameter is non-zero and does not match the current version before update (so the caller is out of sync)
147 * @throws IOException raised if errors occur in the update process
149 virtual int updateText(
150 const char* context, const char* key, const char* value=NULL, time_t expiration=0, int version=0
154 * Deletes an existing "long" record from the storage service.
156 * @param context a storage context label
157 * @param key null-terminated unique key of up to 255 bytes
158 * @return true iff the record existed and was deleted
160 * @throws IOException raised if errors occur in the deletion process
162 virtual bool deleteText(const char* context, const char* key)=0;
165 * Manually trigger a cleanup of expired records.
166 * The method <strong>MAY</strong> return without guaranteeing that
167 * cleanup has already occurred.
169 * @param context a storage context label
171 virtual void reap(const char* context)=0;
174 * Forcibly removes all records in a given context along with any
175 * associated resources devoted to maintaining the context.
177 * @param context a storage context label
179 virtual void deleteContext(const char* context)=0;
186 * Registers StorageService classes into the runtime.
188 void XMLTOOL_API registerStorageServices();
190 /** StorageService based on in-memory caching. */
191 #define MEMORY_STORAGE_SERVICE "org.opensaml.xmlooling.MemoryStorageService"
194 #endif /* __xmltooling_storage_h__ */