package com.implix.jsonrpc;

import java.util.ArrayList;
import java.util.List;

public class ObservableWrapper<T> {
    T object=null;

    List<WrapObserver<T>> observers=new ArrayList<WrapObserver<T>>();

    public void addObserver(WrapObserver<T> observer)
    {
        observers.add(observer);
        if(object!=null)
        {
            observer.update(object);
        }
    }

    public void deleteObserver(WrapObserver<T> observer)
    {
        observers.remove(observer);
    }

    public T get() {
        return object;
    }

    public void set(T object) {
        if(object==null)
        {
            throw new RuntimeException("Do not set null to WrapObserver.");
        }
        this.object = object;
        notifyObservers();
    }

    private void notifyObservers()
    {
        for(int i=observers.size()-1; i>=0;i--)
        {
            observers.get(i).update(object);
        }
    }
}
@@ -22,16 +22,70 @@
 onrpc;%0A%0A
+import android.os.Handler;%0Aimport android.os.Looper;%0A%0A
 import j
@@ -183,16 +183,74 @@
 t=null;%0A
+    Handler handler = new Handler(Looper.getMainLooper());
 %0A    Lis
@@ -902,32 +902,139 @@
 servers()%0A    %7B%0A
+        Runnable runnable = new Runnable() %7B%0A            @Override%0A            public void run() %7B%0A        
         for(int 
@@ -1065,34 +1065,50 @@
 =0;i--)%0A        
+   
-%7B%0A
+     %7B%0A        
             obse
@@ -1140,21 +1140,250 @@
 t);%0A        
-%7D
+        %7D%0A            %7D%0A        %7D;%0A%0A        if(Looper.getMainLooper().getThread().equals(Thread.currentThread()))%0A        %7B%0A            runnable.run();%0A        %7D%0A        else%0A        %7B%0A           handler.post(runnable);%0A        %7D%0A
 %0A    %7D%0A%7D

allow to notify observers from other threads