Android Open Source - MobileCrossPlatformTools Connection Manager






From Project

Back to project page MobileCrossPlatformTools.

License

The source code is released under:

GNU General Public License

If you think the Android project MobileCrossPlatformTools listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package es.tid.weather.http;
/*from w w w  .  j  a  v  a  2s  .  com*/
import java.util.ArrayList;

import org.apache.http.HttpHost;

import android.content.Context;
import android.net.Proxy;

public class ConnectionManager {
    
    public static final int MAX_CONNECTIONS = 5;

    private ArrayList<Runnable> active = new ArrayList<Runnable>();
    private ArrayList<Runnable> queue = new ArrayList<Runnable>();

    private static ConnectionManager instance;
    
    public static HttpHost proxy = null;

    public static ConnectionManager getInstance() {
         if (instance == null)
              instance = new ConnectionManager();
         return instance;
    }

    public static ConnectionManager getInstance(Context context) {
        if (instance == null){
          instance = new ConnectionManager();
          String host = Proxy.getHost(context);
        if (host != null) {
          proxy = new HttpHost(host, Proxy.getPort(context));
        }
        }
        return instance;
   }
    
    public void push(Runnable runnable) {
         queue.add(runnable);
         if (active.size() < MAX_CONNECTIONS)
              startNext();
    }

    private void startNext() {
         if (!queue.isEmpty()) {
              Runnable next = queue.get(0);
              queue.remove(0);
              active.add(next);

              Thread thread = new Thread(next);
              thread.start();
         }
    }

    public void didComplete(Runnable runnable) {
         active.remove(runnable);
         startNext();
    }
    
    public void setProxy(String ip, int port) {
      if (ip != null) {
        proxy = new HttpHost(ip, port);
      } else {
        proxy = null;
      }
    }
}




Java Source Code List

es.tid.weather.common.CurrentWeather.java
es.tid.weather.common.Definitions.java
es.tid.weather.common.WeatherApplication.java
es.tid.weather.common.WeatherDay.java
es.tid.weather.common.Weather.java
es.tid.weather.http.ConnectionManager.java
es.tid.weather.http.HttpConnection.java
es.tid.weather.http.HttpResult.java
es.tid.weather.main.GpsListener.java
es.tid.weather.main.WeatherActivity.java
es.tid.weather.opengl.CubeRenderer.java
es.tid.weather.opengl.Cube.java
es.tid.weather.opengl.TranslucentGLSurfaceViewActivity.java
es.tid.weather.splash.SplashActivity.java