Author: jerome
Date: 2009-02-03 11:50:29 +0100 (Tue, 03 Feb 2009)
New Revision: 3551
Added:
software_suite_v2/software/tuxdroid-gadget-framework/trunk/tuxdroid-gadget-framework/sources/com/kysoh/tuxdroid/gadget/framework/tools/ThreadQueue.java
Modified:
software_suite_v2/software/tuxdroid-gadget-framework/trunk/tuxdroid-gadget-framework/sources/com/kysoh/tuxdroid/gadget/framework/container/GadgetInstance.java
software_suite_v2/software/tuxdroid-gadget-framework/trunk/tuxdroid-gadget-framework/sources/com/kysoh/tuxdroid/gadget/framework/container/NotificationSynchronizer.java
Log:
* Fixed : #126 ?\226?\128?\148 Gadget framework stop issues ( fifo ).
Modified:
software_suite_v2/software/tuxdroid-gadget-framework/trunk/tuxdroid-gadget-framework/sources/com/kysoh/tuxdroid/gadget/framework/container/GadgetInstance.java
===================================================================
---
software_suite_v2/software/tuxdroid-gadget-framework/trunk/tuxdroid-gadget-framework/sources/com/kysoh/tuxdroid/gadget/framework/container/GadgetInstance.java
2009-02-02 18:59:56 UTC (rev 3550)
+++
software_suite_v2/software/tuxdroid-gadget-framework/trunk/tuxdroid-gadget-framework/sources/com/kysoh/tuxdroid/gadget/framework/container/GadgetInstance.java
2009-02-03 10:50:29 UTC (rev 3551)
@@ -36,7 +36,9 @@
public static final String ENVIRONEMENT_PREFIX = "tgp_";
public void abort() {
- if (worker != null) {
+ if(worker != null)
+ {
+
gadget.getContainer().getNotificationSynchronizer().clear(this);
worker.abort();
}
}
@@ -85,25 +87,29 @@
System.out.println(ENVIRONEMENT_PREFIX + parameter.getName() + "=NULL");
}
}
- // for (String key : environement) {
- // System.out.println(key);
- // }
+
shell.setEnvironement(environement.toArray(new
String[environement.size()]));
gadget.listeners.fire().starting(GadgetInstance.this);
gadget.interpreter.run(shell, command);
+
} catch (Throwable e) {
gadget.listeners.fire().errors(GadgetInstance.this, e.getMessage());
- } finally {
+ } finally{
+
while
(gadget.getContainer().getNotificationSynchronizer().hasNotifications(GadgetInstance.this))
{
try {
+
Thread.sleep(500);
- } catch (InterruptedException e) {
- e.printStackTrace();
+ } catch (InterruptedException e)
+ {
+ //Interruption signal received.
}
}
+
synchronized (gadget.instances) {
gadget.instances.remove(this);
}
+
gadget.listeners.fire().stopped(GadgetInstance.this);
}
}
@@ -163,7 +169,6 @@
}
worker = new Worker(command, values);
worker.start();
-
}
// Plus tard, peut-ĂȘtre...
Modified:
software_suite_v2/software/tuxdroid-gadget-framework/trunk/tuxdroid-gadget-framework/sources/com/kysoh/tuxdroid/gadget/framework/container/NotificationSynchronizer.java
===================================================================
---
software_suite_v2/software/tuxdroid-gadget-framework/trunk/tuxdroid-gadget-framework/sources/com/kysoh/tuxdroid/gadget/framework/container/NotificationSynchronizer.java
2009-02-02 18:59:56 UTC (rev 3550)
+++
software_suite_v2/software/tuxdroid-gadget-framework/trunk/tuxdroid-gadget-framework/sources/com/kysoh/tuxdroid/gadget/framework/container/NotificationSynchronizer.java
2009-02-03 10:50:29 UTC (rev 3551)
@@ -24,7 +24,8 @@
import java.util.logging.Logger;
-import net.karmaLab.thread.ThreadQueue;
+import com.kysoh.tuxdroid.gadget.framework.tools.ThreadQueue;
+
import net.karmaLab.traces.Traces;
public class NotificationSynchronizer {
@@ -43,12 +44,15 @@
/** Class logger. */
public synchronized void process() throws Throwable {
current = notifications.get();
-
+
if (current == null) {
return;
}
+
+
current.getGadgetInstance().getGadget().listeners.fire().notification(current.getGadgetInstance(),
current.getId(), current.getParameters());
current = null;
+
}
@Override
@@ -86,7 +90,33 @@
public void add(GadgetNotification notification) {
notifications.add(notification);
}
+
+
+ /**
+ * Remove a notification from stack.
+ * @param notification
+ */
+ public void clear(GadgetInstance instance)
+ {
+ while(true)
+ {
+ boolean test = notifications.remove(instance);
+ try
+ {
+ Worker.sleep(200);
+ }
+ catch (InterruptedException e) {
+ }
+ if(!test)
+ {
+ break;
+ }
+ }
+
+ worker.interrupt();
+ }
+
public boolean hasNotifications(GadgetInstance instance) {
if (current != null && current.getGadgetInstance() == instance)
{
return true;
@@ -96,6 +126,7 @@
return true;
}
}
+
return false;
}
}
Added:
software_suite_v2/software/tuxdroid-gadget-framework/trunk/tuxdroid-gadget-framework/sources/com/kysoh/tuxdroid/gadget/framework/tools/ThreadQueue.java
===================================================================
---
software_suite_v2/software/tuxdroid-gadget-framework/trunk/tuxdroid-gadget-framework/sources/com/kysoh/tuxdroid/gadget/framework/tools/ThreadQueue.java
(rev 0)
+++
software_suite_v2/software/tuxdroid-gadget-framework/trunk/tuxdroid-gadget-framework/sources/com/kysoh/tuxdroid/gadget/framework/tools/ThreadQueue.java
2009-02-03 10:50:29 UTC (rev 3551)
@@ -0,0 +1,105 @@
+/* This file is part of "Karma-Lab Common Toolkits" Library.
+ * Copyright 2006, 2007, 2008, karma-lab.net
+ * Author : Yoran Brault
+ * eMail : softw...@_bad_karma-lab.net (remove _bad_ before sending an
email)
+ * Site : http://artisan.karma-lab.net
+ *
+ * "Karma-Lab Common Toolkits" Library is free software; you can redistribute
it and/or
+ * modify it under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * "Karma-Lab Common Toolkits" Library is distributed in the hope that it will
be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with "Karma-Lab Common Toolkits" Library; if not, write to
the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package com.kysoh.tuxdroid.gadget.framework.tools;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.NoSuchElementException;
+import java.util.logging.Logger;
+
+import net.karmaLab.traces.Traces;
+
+import com.kysoh.tuxdroid.gadget.framework.container.GadgetInstance;
+import com.kysoh.tuxdroid.gadget.framework.container.GadgetNotification;
+
+public class ThreadQueue<T> implements Iterable<T> {
+ /** Class logger. */
+
+ @SuppressWarnings("unused")
+ private static final Logger logger = Traces.LOGGER(ThreadQueue.class);
+ private final LinkedList<T> storage = new LinkedList<T>();
+
+ public void add(T data) {
+ synchronized (storage) {
+ storage.add(data);
+ storage.notify();
+ }
+ }
+
+ public boolean remove(GadgetInstance currentInstance) {
+
+ synchronized(storage)
+ {
+
+ try
+ {
+ GadgetNotification notification =
(GadgetNotification) storage.getFirst();
+
+ if (notification.getGadgetInstance() ==
currentInstance) {
+ storage.remove(storage.getFirst());
+ return true;
+ }
+ }
+ catch(NoSuchElementException noNotifications)
+ {
+ return false;
+ }
+ return false;
+ }
+ }
+
+ public void clear() {
+ synchronized (storage) {
+ storage.clear();
+ storage.notifyAll();
+ }
+ }
+
+ public T get() {
+ synchronized (storage) {
+ if (storage.isEmpty()) {
+ try {
+ storage.wait();
+ } catch (InterruptedException e) {
+ return null;
+ }
+ }
+ if (storage.isEmpty()) {
+ return null;
+ }
+ return storage.removeFirst();
+ }
+ }
+
+ public int size() {
+ synchronized (storage) {
+ return storage.size();
+ }
+ }
+
+ @Override
+ public Iterator<T> iterator() {
+ return storage.iterator();
+ }
+
+}
------------------------------------------------------------------------------
Create and Deploy Rich Internet Apps outside the browser with Adobe(R)AIR(TM)
software. With Adobe AIR, Ajax developers can use existing skills and code to
build responsive, highly engaging applications that combine the power of local
resources and data with the reach of the web. Download the Adobe AIR SDK and
Ajax docs to start building applications today-http://p.sf.net/sfu/adobe-com
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn