Skip to content

Instantly share code, notes, and snippets.

@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>
@arthurtsang
arthurtsang / pom.xml
Last active December 13, 2015 21:58
aggregatable maven report plugin
<plugin>
<groupId>___</groupId>
<artifactId>gemini-maven-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<reportSets>
<reportSet>
<id>gemini graph</id>
<reports>
<report>gemini</report>
<report>aggregate</report>
@arthurtsang
arthurtsang / AggregatorGeminiDoc.java
Created February 18, 2013 22:11
Aggregated Maven Report
@Mojo( name = "aggregate", aggregator = true, requiresDependencyResolution = ResolutionScope.COMPILE)
@Execute( phase = LifecyclePhase.GENERATE_SOURCES )
public class AggregatorGeminiDoc extends GeminiDoc {
@Override
protected boolean isAggregator(){ return true; }
@Override
public boolean canGenerateReport() {
return ( project.getModules().size() > 0);