sPFFramework/src/main/java/it/polimi/spf/framework/services/AppCommunicationAgent.java
public AppServiceProxy getProxy(String componentName) {
		synchronized (this) {

			if (mShutdown) {
				throw new IllegalStateException("Communication agent is shutdown");
			}

			long start = System.nanoTime();

			if (mProxies.containsKey(componentName)) {
				AppServiceProxy proxy = mProxies.get(componentName);
				unscheduleHousekeeper(proxy);
				
				if (proxy.isConnected()) {
					long st = (System.nanoTime() - start) / 1000;
					Log.d(TAG, "HIT for " + componentName + " in " + st + "us");
					
					scheduleHousekeeper(proxy);
					return proxy;
				} else {
					Log.d(TAG, "Removed dead proxy (" + componentName + ")");
					mProxies.remove(proxy);
					// Go on with the creation of new proxy
				}
			}

			AppServiceProxy proxy = new AppServiceProxy(componentName);
			mProxies.put(componentName, proxy);
			Intent serviceIntent = new Intent();
			serviceIntent.setComponent(ComponentName.unflattenFromString(componentName));
			boolean bound = mContext.bindService(serviceIntent, proxy, Context.BIND_AUTO_CREATE);

			if (!bound) {
				Log.e(TAG, "Cannot bound to app service with intent " + componentName);
				return null;
			}

			long st = (System.nanoTime() - start) / 1000;
			Log.d(TAG, "MISS for " + componentName + " in " + st + "us");
			
			scheduleHousekeeper(proxy);
			return proxy;
		}
	}
public AppServiceProxy getProxy(String componentName) {
		synchronized (this) {

			if (mShutdown) {
				throw new IllegalStateException("Communication agent is shutdown");
			}

			long start = System.nanoTime();

			if (mProxies.containsKey(componentName)) {
				AppServiceProxy proxy = mProxies.get(componentName);
				unscheduleHousekeeper(proxy);
				
				if (proxy.isConnected()) {
					long st = (System.nanoTime() - start) / 1000;
					Log.d(TAG, "HIT for " + componentName + " in " + st + "us");
					
					scheduleHousekeeper(proxy);
					return proxy;
				} else {
					Log.d(TAG, "Removed dead proxy (" + componentName + ")");
					mProxies.remove(proxy);
					// Go on with the creation of new proxy
				}
			}

			AppServiceProxy proxy = new AppServiceProxy(componentName);
			mProxies.put(componentName, proxy);
			Intent serviceIntent = new Intent();
			serviceIntent.setComponent(ComponentName.unflattenFromString(componentName));
			boolean bound = mContext.bindService(serviceIntent, proxy, Context.BIND_AUTO_CREATE);

			if (!bound) {
				Log.e(TAG, "Cannot bound to app service with intent " + componentName);
				return null;
			}

			long st = (System.nanoTime() - start) / 1000;
			Log.d(TAG, "MISS for " + componentName + " in " + st + "us");
			
			scheduleHousekeeper(proxy);
			return proxy;
		}
	}
Returns an {@link AppServiceProxy} that can be used to communicate with
the remote service identified by the given component name. If an alive
proxy for the given component name is found in cache, it i returned.
Otherwise, a new proxy is created, stored in the cache and returned.

@param componentName
- the component name of the remote service
@return a proxy to communicate with the remote service