OSGi Bundle Management Code [Part 4, ROM]
In the part 4 of my series I am going to describe the OSGi/Java code on the Plug Computer that implements the bundle manager in the ROM (Remote OSGi Manager) project.... and one of the best parts of doing this particular portion was that I started getting a much better understanding of the XML fundamentals. Notionally I always understood XML, but this was my first time programming with it.
try {ServerSocket ss = new ServerSocket(port);ss.setSoTimeout(soTimeout);System.out.println("\nSocket Server listening on port "+port);while (stopFlag == false) {try {Socket s = ss.accept();clients.addElement(new Worker(s,bc));System.out.println("Worker Thread Created");} catch (Exception ignore) {System.out.println(ignore.getMessage());}}
public void run() {String message = null;String content = null;int option = -1;int BId = -1;String file = "";
try {message = dis.readUTF();System.out.println(message);if (message != null)option = Integer.parseInt((message.split(","))[0]);BId = Integer.parseInt((message.split(","))[1]);file = message.split(",",3)[2];System.out.println("Recd packet from client Option:"+option+" BID:"+BId + " file:"+file);} catch (IOException e1) {System.out.println(e1.getMessage());}//System.out.print("message: "+message+"\n");DoOps getb = new DoOps();
switch (option){case LIST_BUNDLES:content = getb.getBundleList(bc);break;case GET_BUNDLE_INFO:content = getb.getBundleInfo(BId, bc);break;case STOP_BUNDLE:content = getb.stopBundle(BId, bc);break;case START_BUNDLE:content = getb.startBundle(BId, bc);break;case UPDATE_BUNDLE:content = getb.updateBundle(BId, bc,file);break;case SYS_INFO:content = getb.getControllerInfo(bc);break;case INSTALL_BUNDLE:content = getb.installBundle(bc, file);break;}
try {dos.writeUTF(content);dos.flush();dos.writeBoolean(true);this.stopWorker();s.close();return;} catch (IOException e) {System.out.println(e.getMessage());}}
<?xml version="1.0" encoding="UTF-8"?><bundles><bundle id="0"><name>name of bundle</name><status>ACTIVE</status></bundle></bundles>


