Page History
...
Code Block | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||
package ...; import com.blueriq.component.api.store.externalflow.IExternalFlowStore; // other imports ... @Component public class CustomExternalFlowStore implements IExternalFlowStore { @Override public void delete(String key) throws ExternalFlowStoreException, IllegalArgumentException { // add implementation here } @Override public <T extendsObjectModelRetrieval Serializable> T get(String key, Class<T> valueType) throws ExternalFlowStoreException, IllegalArgumentException { // add implementation here return null; } @Override public boolean hasKey(String key) throws ExternalFlowStoreException, IllegalArgumentException { // add implementation here return false; } @Override public void set(String key, SerializableObjectModelStorage value) throws ExternalFlowStoreException, IllegalArgumentException { // add implementation here } } |
Example Hazelcast Datastore
Here is a an example Hazelcast implementation of the datastore.
...
Code Block | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||
package ...; import com.blueriq.component.api.store.externalflow.IExternalFlowStore; // other imports ... @Component public class HazelcastExternalFlowStore implements IExternalFlowStore { private final IMap<String, Serializable>byte[]> map; public HazelcastExternalFlowStore() { ClientConfig config = new ClientConfig(); // configure Hazelcast properties here HazelcastInstance hazelcastInstance = HazelcastClient.newHazelcastClient(config); map = hazelcastInstance.getMap("blueriq"); } @Override public void delete(String key) throws ExternalFlowStoreException, IllegalArgumentException { if (isInvalid(key)) { throw new IllegalArgumentException("Invalid key."); } try { map.delete(key); } catch (Exception e) { throw new ExternalFlowStoreException("Something went wrong", e); } } @Override public <T extends Serializable>ObjectModelRetrieval T get(String key, Class<T> valueType) throws ExternalFlowStoreException, IllegalArgumentException { if (isInvalid(key)) { throw new IllegalArgumentException("Invalid key."); } try { Serializablebyte[] storedValue = map.get(key); if (storedValue == null) { return null; } if (valueType.isInstance(storedValue)) { return valueType.cast(storedValue); } throw new IllegalArgumentException( String.format("Cannot cast from %s to %s.", storedValue.getClass(), valueType)); new ObjectModel(storedValue); } catch (Exception e) { throw new ExternalFlowStoreException("Something went wrong", e); } } @Override public boolean hasKey(String key) throws ExternalFlowStoreException, IllegalArgumentException { if (isInvalid(key)) { throw new IllegalArgumentException("Invalid key."); } try { return map.get(key) != null; } catch (Exception e) { throw new ExternalFlowStoreException("Something went wrong", e); } } @Override public void set(String key, SerializableObjectModelStorage value) throws ExternalFlowStoreException, IllegalArgumentException { if (isInvalid(key)) { throw new IllegalArgumentException("Invalid key."); } if (model == null) { throw new IllegalArgumentException("external flow model must not be null"); } try { map.set(key, value.toBytes(), 1, TimeUnit.MINUTES); } catch (Exception e) { throw new ExternalFlowStoreException("Something went wrong", e); } } private boolean isInvalid(String key) { // define what an invalid key means return false; } } |
...
Overview
Content Tools