<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
- <classpathentry kind="src" path="src/main/resources"/>
+ <classpathentry kind="src" output="target/classes" path="src/main/resources"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/resources"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.argeo.slc</groupId>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
- <executions>
- <execution>
- <goals>
- <goal>test-jar</goal>
- </goals>
- <configuration>
- <archive>
- <manifestFile>src/test/resources/META-INF/MANIFEST.MF</manifestFile>
- </archive>
- </configuration>
- </execution>
- </executions>
+ <!--
+ <executions> <execution> <goals> <goal>test-jar</goal> </goals>
+ <configuration> <archive>
+ <manifestFile>src/test/resources/META-INF/MANIFEST.MF</manifestFile>
+ </archive> </configuration> </execution> </executions>
+ -->
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<Export-Package>
org.argeo.slc.*
</Export-Package>
+ <Import-Package>*,
+ org.springframework.beans.factory.config
+ </Import-Package>
</instructions>
</configuration>
</plugin>
<groupId>org.argeo.slc.runtime</groupId>
<artifactId>org.argeo.slc.support.osgi</artifactId>
</dependency>
-
+
<!-- Unit Tests -->
<dependency>
<groupId>org.argeo.slc.runtime</groupId>
import org.eclipse.core.runtime.adaptor.EclipseStarter;
import org.eclipse.osgi.framework.console.CommandInterpreter;
import org.eclipse.osgi.framework.console.CommandProvider;
-import org.springframework.beans.factory.InitializingBean;
-public class ExecutionCommandProvider implements CommandProvider,
- InitializingBean {
+public class ExecutionCommandProvider implements CommandProvider {
private final static Log log = LogFactory
.getLog(ExecutionCommandProvider.class);
+ private final static String SLC_WITH_REFRESH = "slc";
+ private final static String SLC_NO_REFRESH = "slcnr";
+
private OsgiExecutionModulesManager modulesManager;
private RealizedFlow lastLaunch = null;
public Object _slc(CommandInterpreter ci) {
+ return exec(SLC_WITH_REFRESH, ci);
+ }
+
+ public Object _slcnr(CommandInterpreter ci) {
+ return exec(SLC_NO_REFRESH, ci);
+ }
+
+ protected Object exec(String slcCommand, CommandInterpreter ci) {
// TODO: check version
String firstArg = ci.nextArgument();
if (firstArg == null) {
if (lastLaunch != null) {
- String cmd = "slc " + lastLaunch.getModuleName() + " "
- + lastLaunch.getFlowDescriptor().getName();
+ String cmd = slcCommand + " " + lastLaunch.getModuleName()
+ + " " + lastLaunch.getFlowDescriptor().getName();
if (log.isDebugEnabled())
log.debug("Execute again last command: " + cmd);
return ci.execute(cmd);
}
String executionName = ci.nextArgument();
- launch(firstArg, executionName);
+ launch(slcCommand, firstArg, executionName);
return "COMMAND COMPLETED";
}
- protected void launch(String firstArg, String executionName) {
+ protected void launch(String slcCommand, String firstArg,
+ String executionName) {
lastLaunch = modulesManager.findRealizedFlow(firstArg, executionName);
if (lastLaunch == null)
throw new SlcException("Cannot find launch for " + firstArg + " "
+ executionName);
- modulesManager.updateAndExecute(lastLaunch);
-
+ // Execute
+ if (SLC_WITH_REFRESH.equals(slcCommand))
+ modulesManager.updateAndExecute(lastLaunch);
+ else if (SLC_NO_REFRESH.equals(slcCommand))
+ modulesManager.execute(lastLaunch);
+ else
+ throw new SlcException("Unrecognized SLC command " + slcCommand);
}
public String getHelp() {
StringBuffer buf = new StringBuffer();
buf.append("---SLC Execution Commands---\n");
buf
- .append("\tslc (<id>|<segment of bsn>) <execution bean> - execute an execution flow (without arg, execute last)\n");
+ .append("\tslc (<id>|<segment of bsn>) <execution bean>"
+ + " - refresh the bundle, execute an execution flow (without arg, execute last)\n");
+ buf
+ .append("\tslcnr (<id>|<segment of bsn>) <execution bean>"
+ + " - execute an execution flow (without arg, execute last)\n");
return buf.toString();
}
this.modulesManager = osgiModulesManager;
}
- public void afterPropertiesSet() throws Exception {
+ public void init() throws Exception {
final String module = System.getProperty("slc.launch.module");
final String executionName = System.getProperty("slc.launch.execution");
if (module != null) {
@Override
public void run() {
try {
- launch(module, executionName);
+ launch(SLC_NO_REFRESH, module, executionName);
// in case of failure OSGi runtime stays up and last
// launch can be used to debug by calling 'slc'
} catch (Exception e) {
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-2.5.xsd\r
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">\r
\r
- <bean id="bundlesManager" class="org.argeo.slc.osgi.BundlesManager" />\r
+ <bean\r
+ class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">\r
+ <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />\r
+ <property name="ignoreUnresolvablePlaceholders" value="false" />\r
+ <property name="locations">\r
+ <value>osgibundle:equinox.properties\r
+ </value>\r
+ </property>\r
+ </bean>\r
+\r
+ <bean id="commandProvider" class="org.argeo.slc.equinox.ExecutionCommandProvider"\r
+ init-method="init">\r
+ <property name="modulesManager" ref="modulesManager" />\r
+ </bean>\r
+\r
+ <bean id="bundlesManager" class="org.argeo.slc.osgi.BundlesManager">\r
+ <property name="defaultTimeout" value="${slc.equinox.commandTimeout}" />\r
+ <property name="pollingPeriod" value="${slc.equinox.commandPollingPeriod}" />\r
+ </bean>\r
\r
<bean id="modulesManager" class="org.argeo.slc.osgi.OsgiExecutionModulesManager">\r
<property name="bundlesManager" ref="bundlesManager" />\r
http://www.springframework.org/schema/beans \r
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">\r
\r
- <service interface="org.eclipse.osgi.framework.console.CommandProvider">\r
- <beans:bean class="org.argeo.slc.equinox.ExecutionCommandProvider">\r
- <beans:property name="modulesManager" ref="modulesManager" />\r
- </beans:bean>\r
- </service>\r
+ <service interface="org.eclipse.osgi.framework.console.CommandProvider"\r
+ ref="commandProvider" />\r
\r
</beans:beans>
\ No newline at end of file
--- /dev/null
+# Timeout for the SLC command in the OSGi console (in ms)
+slc.equinox.commandTimeout=10000
+# Polling period for synchronous OSGi commands (in ms)
+slc.equinox.commandPollingPeriod=100
\ No newline at end of file
import java.util.ArrayList;
import java.util.List;
-import java.util.Map;
-import java.util.TreeMap;
import org.argeo.slc.equinox.unit.AbstractOsgiRuntimeTestCase;
import org.argeo.slc.osgiboot.OsgiBoot;
private BundleContext bundleContext;
private Long defaultTimeout = 10000l;
+ private Long pollingPeriod = 100l;
+
+ // Refresh sync objects
private final Object refreshedPackageSem = new Object();
+ private Boolean packagesRefreshed = false;
/**
* Stop the module, update it, refresh it and restart it. All synchronously.
public void upgradeSynchronous(OsgiBundle osgiBundle) {
try {
Bundle bundle = findRelatedBundle(osgiBundle);
+
+ long begin = System.currentTimeMillis();
+
+ long bStop = begin;
stopSynchronous(bundle);
+
+ long bUpdate = System.currentTimeMillis();
updateSynchronous(bundle);
+
// Refresh in case there are fragments
+ long bRefresh = System.currentTimeMillis();
refreshSynchronous(bundle);
+
+ long bStart = System.currentTimeMillis();
startSynchronous(bundle);
+ long aStart = System.currentTimeMillis();
+ if (log.isDebugEnabled()) {
+ log.debug("OSGi upgrade performed in " + (aStart - begin)
+ + "ms for bundle " + osgiBundle);
+ log.debug(" stop \t: " + (bUpdate - bStop) + "ms");
+ log.debug(" update\t: " + (bRefresh - bUpdate) + "ms");
+ log.debug(" refresh\t: " + (bStart - bRefresh) + "ms");
+ log.debug(" start\t: " + (aStart - bStart) + "ms");
+ log.debug(" TOTAL\t: " + (aStart - begin) + "ms");
+ }
+
+ long bAppContext = System.currentTimeMillis();
String filter = "(Bundle-SymbolicName=" + bundle.getSymbolicName()
+ ")";
// Wait for application context to be ready
// TODO: use service tracker
getServiceRefSynchronous(ApplicationContext.class.getName(), filter);
+ long aAppContext = System.currentTimeMillis();
+ long end = aAppContext;
+
+ if (log.isDebugEnabled()) {
+ log.debug("Application context refresh performed in "
+ + (aAppContext - bAppContext) + "ms for bundle "
+ + osgiBundle);
+ log.debug(" TOTAL\t: " + (aAppContext - bAppContext) + "ms");
+ }
if (log.isDebugEnabled())
log.debug("Bundle " + bundle.getSymbolicName()
- + " ready to be used at latest version.");
+ + " ready to be used at latest version."
+ + " (upgrade performed in " + (end - begin) + "ms).");
+ log.debug(" TOTAL\t: " + (end - begin) + "ms");
} catch (Exception e) {
throw new SlcException("Cannot update bundle " + osgiBundle, e);
}
/** Updates bundle synchronously. */
protected void updateSynchronous(Bundle bundle) throws BundleException {
- // int originalState = bundle.getState();
bundle.update();
boolean waiting = true;
|| state == Bundle.RESOLVED)
waiting = false;
- sleep(100);
- if (System.currentTimeMillis() - begin > defaultTimeout)
- throw new SlcException("Update of bundle "
- + bundle.getSymbolicName()
- + " timed out. Bundle state = " + bundle.getState());
+ sleepWhenPolling();
+ checkTimeout(begin, "Update of bundle " + bundle.getSymbolicName()
+ + " timed out. Bundle state = " + bundle.getState());
} while (waiting);
if (log.isTraceEnabled())
if (bundle.getState() == Bundle.ACTIVE)
waiting = false;
- sleep(100);
- if (System.currentTimeMillis() - begin > defaultTimeout)
- throw new SlcException("Start of bundle "
- + bundle.getSymbolicName()
- + " timed out. Bundle state = " + bundle.getState());
+ sleepWhenPolling();
+ checkTimeout(begin, "Start of bundle " + bundle.getSymbolicName()
+ + " timed out. Bundle state = " + bundle.getState());
} while (waiting);
if (log.isTraceEnabled())
&& bundle.getState() != Bundle.STOPPING)
waiting = false;
- sleep(100);
- if (System.currentTimeMillis() - begin > defaultTimeout)
- throw new SlcException("Stop of bundle "
- + bundle.getSymbolicName()
- + " timed out. Bundle state = " + bundle.getState());
+ sleepWhenPolling();
+ checkTimeout(begin, "Stop of bundle " + bundle.getSymbolicName()
+ + " timed out. Bundle state = " + bundle.getState());
} while (waiting);
if (log.isTraceEnabled())
PackageAdmin packageAdmin = (PackageAdmin) bundleContext
.getService(packageAdminRef);
Bundle[] bundles = { bundle };
- packageAdmin.refreshPackages(bundles);
+ long begin = System.currentTimeMillis();
synchronized (refreshedPackageSem) {
+ packagesRefreshed = false;
+ packageAdmin.refreshPackages(bundles);
try {
refreshedPackageSem.wait(defaultTimeout);
} catch (InterruptedException e) {
// silent
}
+ if (!packagesRefreshed) {
+ long now = System.currentTimeMillis();
+ throw new SlcException("Packages not refreshed after "
+ + (now - begin) + "ms");
+ } else {
+ packagesRefreshed = false;
+ }
}
if (log.isTraceEnabled())
public void frameworkEvent(FrameworkEvent event) {
if (event.getType() == FrameworkEvent.PACKAGES_REFRESHED) {
synchronized (refreshedPackageSem) {
+ packagesRefreshed = true;
refreshedPackageSem.notifyAll();
}
}
if (sfs != null)
waiting = false;
- sleep(100);
+ sleepWhenPolling();
if (System.currentTimeMillis() - begin > defaultTimeout)
throw new SlcException("Search of services " + clss
+ " with filter " + filter + " timed out.");
return sfs;
}
- protected void sleep(long ms) {
+ protected void checkTimeout(long begin, String msg) {
+ long now = System.currentTimeMillis();
+ if (now - begin > defaultTimeout)
+ throw new SlcException(msg + " (timeout after " + (now - begin)
+ + "ms)");
+
+ }
+
+ protected void sleepWhenPolling() {
try {
- Thread.sleep(ms);
+ Thread.sleep(pollingPeriod);
} catch (InterruptedException e) {
// silent
}
return bundleContext;
}
+ public void setPollingPeriod(Long pollingPeriod) {
+ this.pollingPeriod = pollingPeriod;
+ }
+
}