Author: furfari
Date: Tue Aug 5 13:37:00 2008
New Revision: 682934
URL: http://svn.apache.org/viewvc?rev=682934&view=rev
Log:
FELIX-642 modified BinaryLigth to instantiate several devices by means a system
property(-Ddevices.count=<#devices>)
Modified:
felix/sandbox/furfari/Bug-642/binarylight/src/main/java/org/apache/felix/upnp/sample/binaryLight/Activator.java
felix/sandbox/furfari/Bug-642/binarylight/src/main/java/org/apache/felix/upnp/sample/binaryLight/devices/LightDevice.java
Modified:
felix/sandbox/furfari/Bug-642/binarylight/src/main/java/org/apache/felix/upnp/sample/binaryLight/Activator.java
URL:
http://svn.apache.org/viewvc/felix/sandbox/furfari/Bug-642/binarylight/src/main/java/org/apache/felix/upnp/sample/binaryLight/Activator.java?rev=682934&r1=682933&r2=682934&view=diff
==============================================================================
---
felix/sandbox/furfari/Bug-642/binarylight/src/main/java/org/apache/felix/upnp/sample/binaryLight/Activator.java
(original)
+++
felix/sandbox/furfari/Bug-642/binarylight/src/main/java/org/apache/felix/upnp/sample/binaryLight/Activator.java
Tue Aug 5 13:37:00 2008
@@ -40,40 +40,77 @@
public class Activator implements BundleActivator {
static BundleContext context;
- private ServiceRegistration serviceRegistration;
- private LightDevice light;
+ private ServiceRegistration[] serviceRegistration;
+ private LightDevice[] light;
private HttpService httpServ;
+ final int COUNT =
Integer.parseInt(System.getProperty("devices.count","25"));
+ private boolean finished = false;
+ public class LightThread extends Thread{
+ private int i;
+
+ public LightThread(int i){
+ this.i=i;
+ }
+ public void run(){
+ doServiceRegistration(i);
+ }
+ }
+
+
/**
* @see
org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext)
*/
public void start(BundleContext context) throws Exception {
Activator.context = context;
- doServiceRegistration();
- doServletRegistration();
+ serviceRegistration = new ServiceRegistration[COUNT];
+ light = new LightDevice[COUNT];
+ for( int i= 0; i < COUNT; i++){
+ new LightThread(i).start();
+ //doServletRegistration(i);
+ }
+
+ new Thread(){
+ public void run(){
+ while (! finished){
+ try {
+ Thread.sleep(180000);
+ if (! finished){
+ for(int i= 0; i <
COUNT; i++){
+ LightModel
model = light[i].getModel();
+
model.doSwitch(! model.getStatus());
+ }
+ }
+ } catch (InterruptedException e) {
+ return;
+ }
+ }
+ }
+ }.start();
+
}
- private void doServiceRegistration() {
- light = new LightDevice(context);
- Dictionary dict = light.getDescriptions(null);
+ private void doServiceRegistration(int i) {
+ light[i] = new LightDevice(context,i);
+ Dictionary dict = light[i].getDescriptions(null);
- serviceRegistration = context.registerService(
+ serviceRegistration[i] = context.registerService(
UPnPDevice.class.getName(),
- light,
+ light[i],
dict
);
}
- private void doServletRegistration() {
+ private void doServletRegistration(int i) {
ServiceReference sr =
context.getServiceReference(HttpService.class.getName());
if (sr != null) {
httpServ = (HttpService) context.getService(sr);
try {
- Servlet presentationServlet = new
PresentationServlet(light
+ Servlet presentationServlet = new
PresentationServlet(light[i]
.getModel());
- httpServ.registerServlet("/upnp/binaryLight",
+ httpServ.registerServlet("/upnp/binaryLight/"+i,
presentationServlet, null,
null);
} catch (Exception e) {
System.err.println("Exception registering
presentationServlet:"
@@ -95,7 +132,10 @@
* @see
org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext)
*/
public void stop(BundleContext context) throws Exception {
- serviceRegistration.unregister();
- light.close();
+ finished = true;
+ for(int i= 0; i < COUNT; i++){
+ serviceRegistration[i].unregister();
+ light[i].close();
+ }
}
}
Modified:
felix/sandbox/furfari/Bug-642/binarylight/src/main/java/org/apache/felix/upnp/sample/binaryLight/devices/LightDevice.java
URL:
http://svn.apache.org/viewvc/felix/sandbox/furfari/Bug-642/binarylight/src/main/java/org/apache/felix/upnp/sample/binaryLight/devices/LightDevice.java?rev=682934&r1=682933&r2=682934&view=diff
==============================================================================
---
felix/sandbox/furfari/Bug-642/binarylight/src/main/java/org/apache/felix/upnp/sample/binaryLight/devices/LightDevice.java
(original)
+++
felix/sandbox/furfari/Bug-642/binarylight/src/main/java/org/apache/felix/upnp/sample/binaryLight/devices/LightDevice.java
Tue Aug 5 13:37:00 2008
@@ -42,7 +42,7 @@
public class LightDevice implements UPnPDevice {
- final private String DEVICE_ID = "uuid:Felix-BinaryLight+"
+Integer.toHexString(new Random(System.currentTimeMillis()).nextInt());
+ private String DEVICE_ID = "uuid:Felix-BinaryLight+"
+Integer.toHexString(new Random(System.currentTimeMillis()).nextInt());
private BundleContext context;
private LightModel model;
private LightUI ui;
@@ -51,8 +51,9 @@
private Dictionary dictionary;
private UPnPEventNotifier notifier;
- public LightDevice(BundleContext context) {
+ public LightDevice(BundleContext context,int i) {
this.context=context;
+ DEVICE_ID = DEVICE_ID + "_" +i;
model = new LightModel();
ui = new LightUI(model);
powerSwitch = new PowerSwitchService(model);