From cd84b915b35bdfc8da41ff014296c180eca9cfa8 Mon Sep 17 00:00:00 2001 From: DmitriyMX Date: Mon, 15 Aug 2016 22:47:21 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BC=D0=BE=D0=B4=D1=83=D0=BB=D1=8F=20Com?= =?UTF-8?q?mons:=20=D1=81=D1=82=D0=B0=D0=BD=D0=B4=D0=B0=D1=80=D1=82=D0=BD?= =?UTF-8?q?=D0=B0=D1=8F=20=D0=BA=D0=BE=D0=BC=D0=B0=D0=BD=D0=B4=D0=B0=20exi?= =?UTF-8?q?t?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Commons/pom.xml | 9 ++++-- .../src/main/java/asys/commons/Activator.java | 9 ++++-- .../src/main/java/asys/commons/Commands.java | 29 +++++++++++++++++++ 3 files changed, 42 insertions(+), 5 deletions(-) create mode 100644 Commons/src/main/java/asys/commons/Commands.java 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) { + } + } +}