Skip to content

Instantly share code, notes, and snippets.

@arthurtsang
arthurtsang / pom.xml
Created February 18, 2013 18:58
POM for maven report plugin
<packaging>maven-plugin</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.2</version>
<configuration>
<!-- see http://jira.codehaus.org/browse/MNG-5346 -->
@arthurtsang
arthurtsang / GeminiDoc.java
Last active December 13, 2015 21:58
Custom Maven Report
@Mojo( name="gemini", requiresDependencyResolution = ResolutionScope.COMPILE )
@Execute( phase = LifecyclePhase.GENERATE_SOURCES )
public class GeminiDoc extends AbstractMavenReport {
@Component
protected MavenProject project;
@Parameter( defaultValue = "${reactorProjects}", readonly = true)
protected List<MavenProject> reactorProjects;
@Override
@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);
@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 / 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 / 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 / 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 / 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 / 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 / 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;