Skip to content

Instantly share code, notes, and snippets.

@arthurtsang
arthurtsang / ZooInstall.java
Last active December 15, 2015 13:29
ZooKeeper watcher without loosing events
private void getConfigsFromZookeeper() throws IOException {
logger.debug("Connected to Zookeeper");
synchronized(lock) {
try {
configs = trackChildren(configs);
} catch (Exception e) {
logger.error("Error tracking Zookeeper config", e);
}
}
}
@arthurtsang
arthurtsang / hpui-springintegration-extension.xsd
Last active December 15, 2015 12:28
using spring tool to verify the type of bean object
<xs:annotation>
<xs:documentation>
The input channel of the chain.
</xs:documentation>
<xs:appinfo>
<tool:annotation kind="ref">
<tool:expected-type type="org.springframework.integration.channel.DirectChannel" />
</tool:annotation>
</xs:appinfo>
</xs:annotation>
@arthurtsang
arthurtsang / applicationContext-test-springintegration.xml
Created March 25, 2013 19:17
dynamic service activator with custom namespace
<int-ext:dynamic-service-activator id="dynamicServiceActivator">
<int-ext:method name="getService" expression="@bean.getService(headers['serviceId'],payload)" reply-channel="serviceResponse"/>
<int-ext:method name="getServices" expression="@bean.getServices(headers['user'])" reply-channel="aggregateSvcRequests" />
</int-ext:dynamic-service-activator>
@arthurtsang
arthurtsang / module-context.xml
Last active December 15, 2015 09:39
dynamic service activator
<bean id="svcDynamicServiceActivator" class="DynamicServiceActivator">
<property name="expressionToReplyChannel">
<map>
<entry>
<key><value>getServices</value></key>
<list>
<value>@bean.getServices(headers['user'])</value>
<value>aggregateSvcRequests</value>
</list>
</entry>
@arthurtsang
arthurtsang / OsgiBundleApplicationContextHelperImpl.java
Created March 24, 2013 22:51
Maintain a list of service dependiency using OsgiBundleApplicationContextListener
@Override
public void onOsgiApplicationEvent(OsgiBundleApplicationContextEvent event) {
if( event instanceof BootstrappingDependencyEvent) {
BootstrappingDependencyEvent bootstrappingDependencyEvent = (BootstrappingDependencyEvent)event;
OsgiServiceDependencyEvent osgiServiceDependencyEvent = bootstrappingDependencyEvent.getDependencyEvent();
OsgiServiceDependency osgiServiceDependency = osgiServiceDependencyEvent.getServiceDependency();
Bundle bundle = bootstrappingDependencyEvent.getBundle();
BundleId bundleId = new BundleId(bundle.getBundleId(),bundle.getSymbolicName());
BeanId beanId = new BeanId(osgiServiceDependency.getBeanName(),osgiServiceDependency.getServiceFilter().toString());
ServiceStatus status = null;
@arthurtsang
arthurtsang / OHashCacheOperations.java
Created March 24, 2013 22:11
calling redis script using Redis Template
template.execute(new RedisCallback<Object>() {
@Override
public Object doInRedis(RedisConnection connection) throws DataAccessException {
Jedis jedis = (Jedis) connection.getNativeConnection();
RedisSerializer<Object> redisSerializer = (RedisSerializer<Object>) template.getHashValueSerializer();
String json = new String( redisSerializer.serialize(value) );
return jedis.eval(UPDATE_OHASH_SCRIPT, 2, listKey, hashKey, id, json);
}
});
@arthurtsang
arthurtsang / LuaScripts.java
Created March 24, 2013 22:10
LUA script to update a list & a hash cache together
protected static final String UPDATE_OHASH_SCRIPT =
"local listkey = KEYS[1];" +
"local hashkey = KEYS[2];" +
"local id = ARGV[1];" +
"local item = ARGV[2];" +
"local found = false;" +
"local ids = redis.call('lrange', listkey, 0, -1 );" +
"for i = 1,#ids do " +
"if id == ids[i] then " +
"found = true;" +
@arthurtsang
arthurtsang / stacktrace
Last active December 15, 2015 08:49
dead lock - creating bean in gemini managed properties update method
"EclipseGeminiBlueprintExtenderThread-44" prio=10 tid=0x00007fcd504a1000 nid=0xf83 waiting for monitor entry [0x00007fcd3f3ed000]
java.lang.Thread.State: BLOCKED (on object monitor)
at org.eclipse.gemini.blueprint.compendium.internal.cm.ConfigurationAdminManager.initialize(ConfigurationAdminManager.java:124)
- waiting to lock <0x00000007e07bf460> (a java.lang.Object)
at org.eclipse.gemini.blueprint.compendium.internal.cm.ConfigurationAdminManager.getConfiguration(ConfigurationAdminManager.java:98)
at org.eclipse.gemini.blueprint.compendium.internal.cm.DefaultManagedServiceBeanManager.register(DefaultManagedServiceBeanManager.java:56)
at org.eclipse.gemini.blueprint.compendium.internal.cm.ManagedServiceInstanceTrackerPostProcessor.postProcessBeforeInitialization(ManagedServiceInstanceTrackerPostProcessor.java:61)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcesso
@arthurtsang
arthurtsang / module-context.xml
Last active December 15, 2015 08:49
osgi managed properties
<bean id ="indexConfigMgr" class="...index.manager.impl.ElasticSearchIndexConfigManagerImpl" depends-on="indexTemplate">
<property name="esClient" ref="esClient" />
<osgix:managed-properties persistent-id="...elasticsearch.index" update-method="updateConfig"/>
</bean>
@arthurtsang
arthurtsang / module-context.xml
Last active December 15, 2015 08:48
managed service factory
<osgix:managed-service-factory id="cache-config-redis" factory-pid="...cache.redis" interface="...cache.Cache">
<bean class="...cache.impl.RedisCacheImpl">
<property name="redisConnectionFactory" ref="jedisConnectionFactory"/>
</bean>
</osgix:managed-service-factory>