diff --git a/Commons/pom.xml b/Commons/pom.xml index d7d5e1c..bce2a28 100644 --- a/Commons/pom.xml +++ b/Commons/pom.xml @@ -19,20 +19,25 @@ asys commons - 0.1.3 + 0.2 bundle asys api - 0.4 + 0.7 org.osgi org.osgi.core 6.0.0 + + org.apache.felix + org.apache.felix.gogo.runtime + 0.10.0 + diff --git a/Commons/src/main/java/asys/commons/Activator.java b/Commons/src/main/java/asys/commons/Activator.java index 3b320f6..6b41b3b 100644 --- a/Commons/src/main/java/asys/commons/Activator.java +++ b/Commons/src/main/java/asys/commons/Activator.java @@ -4,21 +4,24 @@ */ package asys.commons; +import asys.api.ASysUtils; import asys.api.BankObject; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceRegistration; public class Activator implements BundleActivator { - private ServiceRegistration service; + private ServiceRegistration serviceBankObjects, serviceCmd; @Override public void start(BundleContext bundleContext) throws Exception { - service = bundleContext.registerService(BankObject.class.getName(), new SimpleBankObject(), null); + serviceCmd = ASysUtils.RegisterCommands(bundleContext, new Commands(bundleContext.getBundle(0L)), "asys"); + serviceBankObjects = bundleContext.registerService(BankObject.class.getName(), new SimpleBankObject(), null); } @Override public void stop(BundleContext bundleContext) throws Exception { - service.unregister(); + serviceBankObjects.unregister(); + serviceCmd.unregister(); } } diff --git a/Commons/src/main/java/asys/commons/Commands.java b/Commons/src/main/java/asys/commons/Commands.java new file mode 100644 index 0000000..3e209a7 --- /dev/null +++ b/Commons/src/main/java/asys/commons/Commands.java @@ -0,0 +1,29 @@ +/* + * DmitriyMX + * 2016-08-15 + */ +package asys.commons; + +import asys.api.ASysUtils; +import asys.api.Command; +import org.apache.felix.service.command.Descriptor; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleException; + +public class Commands { + private Bundle systemBundle; + + public Commands(Bundle systemBundle) { + this.systemBundle = systemBundle; + } + + @Command + @Descriptor("Завершить работу платформы ASys") + public void exit() { + try { + ASysUtils.Log("ASys shutdown..."); + systemBundle.stop(); + } catch (BundleException ignore) { + } + } +}