INT-3691 Add ZookeeperMetadataStore
JIRA: https://jira.spring.io/browse/INT-3691 - create new core interfaces `ListenableMetadataStore` and `MessageStoreListener`; - create new module `spring-integration-zookeeper`; - add `ZookeeperMetadataStore` implementation Polishing Polishing - moved classes into core/test where necessary, including conversion methods - properly renamed `MetadataStoreListenerAdapter`
This commit is contained in:
committed by
Gary Russell
parent
51b52ea3a6
commit
8782d097cf
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.metadata;
|
||||
|
||||
/**
|
||||
*
|
||||
* {@link ConcurrentMetadataStore} with the ability of registering {@link MetadataStoreListener} callbacks, to be
|
||||
* invoked when changes occur in the metadata store.
|
||||
*
|
||||
* @author Marius Bogoevici
|
||||
*/
|
||||
public interface ListenableMetadataStore extends ConcurrentMetadataStore {
|
||||
|
||||
/**
|
||||
* Registers a listener with the metadata store
|
||||
*
|
||||
* @param callback the callback to be registered
|
||||
*/
|
||||
void addListener(MetadataStoreListener callback);
|
||||
|
||||
/**
|
||||
* Unregisters a listener
|
||||
*
|
||||
* @param callback the callback to be unregistered
|
||||
*/
|
||||
void removeListener(MetadataStoreListener callback);
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright 2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.metadata;
|
||||
|
||||
/**
|
||||
* A callback to be invoked whenever a value changes in the data store.
|
||||
*
|
||||
* @author Marius Bogoevici
|
||||
*/
|
||||
public interface MetadataStoreListener {
|
||||
|
||||
/**
|
||||
* Invoked when a key is added to the store
|
||||
*
|
||||
* @param key the key being added
|
||||
* @param value the value being added
|
||||
*/
|
||||
void onAdd(String key, String value);
|
||||
|
||||
/**
|
||||
* Invoked when a key is removed from the store
|
||||
*
|
||||
* @param key the key being removed
|
||||
* @param oldValue the value being removed
|
||||
*/
|
||||
void onRemove(String key, String oldValue);
|
||||
|
||||
/**
|
||||
* Invoked when a key is updated into the store
|
||||
* @param key the key being updated
|
||||
* @param newValue the new value
|
||||
*/
|
||||
void onUpdate(String key, String newValue);
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.metadata;
|
||||
|
||||
/**
|
||||
* Base implementation for a {@link MetadataStoreListener}. Subclasses may override any of the methods.
|
||||
*
|
||||
* @author Marius Bogoevici
|
||||
*/
|
||||
public abstract class MetadataStoreListenerAdapter implements MetadataStoreListener {
|
||||
|
||||
@Override
|
||||
public void onAdd(String key, String value) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemove(String key, String oldValue) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate(String key, String newValue) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014 the original author or authors.
|
||||
* Copyright 2014-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package org.springframework.integration.support.utils;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
@@ -23,11 +25,13 @@ import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.integration.support.DefaultMessageBuilderFactory;
|
||||
import org.springframework.integration.support.MessageBuilderFactory;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* General utility methods.
|
||||
*
|
||||
* @author Gary Russell
|
||||
* @author Marius Bogoevici
|
||||
* @since 4.0
|
||||
*
|
||||
*/
|
||||
@@ -98,4 +102,37 @@ public class IntegrationUtils {
|
||||
return beanFactory.getBean(beanName, type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility method for null-safe conversion from String to byte[]
|
||||
*
|
||||
* @param value the String to be converted
|
||||
* @param encoding the encoding
|
||||
* @return the byte[] corresponding to the given String and encoding, null if provided String argument was null
|
||||
* @throws IllegalArgumentException if the encoding is not supported
|
||||
*/
|
||||
public static byte[] stringToBytes(String value, String encoding) {
|
||||
try {
|
||||
return value != null ? value.getBytes(encoding) : null;
|
||||
}
|
||||
catch (UnsupportedEncodingException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility method for null-safe conversion from byte[] to String
|
||||
*
|
||||
* @param bytes the byte[] to be converted
|
||||
* @param encoding the encoding
|
||||
* @return the String corresponding to the given byte[] and encoding, null if provided byte[] argument was null
|
||||
* @throws IllegalArgumentException if the encoding is not supported
|
||||
*/
|
||||
public static String bytesToString(byte[] bytes, String encoding) {
|
||||
try {
|
||||
return bytes == null ? null : new String(bytes, encoding);
|
||||
}
|
||||
catch (UnsupportedEncodingException e) {
|
||||
throw new IllegalArgumentException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user