com.couchbase.client
Class ViewConnection

java.lang.Object
  extended by net.spy.memcached.compat.SpyObject
      extended by com.couchbase.client.ViewConnection
All Implemented Interfaces:
Reconfigurable

public class ViewConnection
extends net.spy.memcached.compat.SpyObject
implements Reconfigurable

The ViewConnection class creates and manages the various connections to the ViewNodes.


Field Summary
protected  boolean reconfiguring
           
protected  boolean running
           
 
Constructor Summary
ViewConnection(CouchbaseConnectionFactory cf, java.util.List<java.net.InetSocketAddress> addrs, java.util.Collection<net.spy.memcached.ConnectionObserver> obs)
          Kickstarts the initialization and delegates the connection creation.
 
Method Summary
 void addOp(HttpOperation op)
          Write an operation to the next ViewNode.
protected  void checkState()
          Checks the state of the ViewConnection.
 java.util.List<ViewNode> getConnectedNodes()
          Returns the currently connected ViewNodes.
 void reconfigure(Bucket bucket)
          Reconfigures the connected ViewNodes.
 boolean shutdown()
          Initiates the shutdown of all connected ViewNodes.
 
Methods inherited from class net.spy.memcached.compat.SpyObject
getLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

reconfiguring

protected volatile boolean reconfiguring

running

protected volatile boolean running
Constructor Detail

ViewConnection

public ViewConnection(CouchbaseConnectionFactory cf,
                      java.util.List<java.net.InetSocketAddress> addrs,
                      java.util.Collection<net.spy.memcached.ConnectionObserver> obs)
               throws java.io.IOException
Kickstarts the initialization and delegates the connection creation.

Parameters:
cf - the factory which contains neeeded information.
addrs - the list of addresses to connect to.
obs - the connection observers.
Throws:
java.io.IOException
Method Detail

addOp

public void addOp(HttpOperation op)
Write an operation to the next ViewNode. To make sure that the operations are distributed throughout the cluster, the ViewNode is changed every time a new operation is added. Since the getNextNode() method increments the ViewNode IDs and calculates the modulo, the nodes are selected in a round-robin fashion.

Parameters:
op - the operation to run.

getConnectedNodes

public java.util.List<ViewNode> getConnectedNodes()
Returns the currently connected ViewNodes.

Returns:
a list of currently connected ViewNodes.

checkState

protected void checkState()
Checks the state of the ViewConnection. If shutdown is currently in progress, an Exception is thrown.


shutdown

public boolean shutdown()
                 throws java.io.IOException
Initiates the shutdown of all connected ViewNodes.

Returns:
false if a connection is already in progress, true otherwise.
Throws:
java.io.IOException

reconfigure

public void reconfigure(Bucket bucket)
Reconfigures the connected ViewNodes. When a reconfiguration event happens, new ViewNodes may need to be added or old ones need to be removed from the current configuration. This method takes care that those operations are performed in the correct order and are executed in a thread-safe manner.

Specified by:
reconfigure in interface Reconfigurable
Parameters:
bucket - the bucket which has been rebalanced.


Copyright © 2006-2009 Dustin Sallings, 2009-2012 Couchbase, Inc.