package org.wzj.memcached.node;

import java.net.InetSocketAddress;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicBoolean;

import org.jboss.netty.bootstrap.ClientBootstrap;
import org.jboss.netty.channel.ChannelFactory;
import org.jboss.netty.channel.ChannelFuture;
import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory;
import org.wzj.memcached.MemcachedChannelPipelineFactory;


/**
 * 
 * @author Wen
 *
 */
public class Connection {

	private static final Connection INSTANCE = new Connection();

	private ChannelFactory channelFactory;

	private ClientBootstrap boostrap;
	
	private   AtomicBoolean init = new AtomicBoolean(false) ;

	private Connection() {

	}

	public ChannelFuture connect(InetSocketAddress remoteAdd) {
		
		if(init.get() == false ){
			throw new RuntimeException(" Not initialized ") ;
		}
		
		return boostrap.connect(remoteAdd);
	}

	public static Connection getInstance() {
		return INSTANCE;
	}
	
	public void shutdown(){
		boostrap.releaseExternalResources();
	}

	public void init(String[] servers) {
		synchronized(init){
			if(init.get() == false ){
			channelFactory = new NioClientSocketChannelFactory(
					Executors.newCachedThreadPool(),
					Executors.newCachedThreadPool(),  servers.length   );
			boostrap = new ClientBootstrap(channelFactory);

			boostrap.setPipelineFactory(new MemcachedChannelPipelineFactory());
			
			init.set(true);
		}
		
		}
		
	}

}

@@ -662,23 +662,17 @@
 ivate   
-AtomicB
+b
 oolean i
@@ -681,32 +681,13 @@
 t = 
-new AtomicBoolean(
 false
-)
  ;%0D%0A
@@ -788,38 +788,32 @@
 %7B%0D%0A%09%09%0D%0A%09%09if(init
-.get()
  == false )%7B%0D%0A%09%09
@@ -1050,24 +1050,46 @@
 sources();%0D%0A
+%09%09%0D%0A%09%09init = false ;%0D%0A
 %09%7D%0D%0A%0D%0A%09publi
@@ -1127,30 +1127,10 @@
 %0D%0A%09%09
-synchronized(init)%7B
 %0D%0A
-%09
 %09%09if
@@ -1138,29 +1138,33 @@
 init
-.get() == false )%7B%0D%0A%09
+ == true ) return ;%0D%0A%09%09%0D%0A
 %09%09ch
@@ -1214,25 +1214,24 @@
 ctory(%0D%0A%09%09%09%09
-%09
 Executors.ne
@@ -1252,17 +1252,16 @@
 ool(),%0D%0A
-%09
 %09%09%09%09Exec
@@ -1311,17 +1311,16 @@
 h   );%0D%0A
-%09
 %09%09boostr
@@ -1366,17 +1366,16 @@
 );%0D%0A%0D%0A%09%09
-%09
 boostrap
@@ -1441,47 +1441,26 @@
 %0D%0A%09%09
-%09
 %0D%0A%09%09
-%09
 init
-.set(true);%0D%0A%09%09%7D%0D%0A%09%09%0D%0A%09%09%7D%0D%0A%09%09
+  = true ;
 %0D%0A%09%7D

Change the init to a boolean type