test_class.file: tigase-server 7.1.0/src/test/java/tigase/cluster/ClusterConnectionSelectorTest.java
test_class.identifier: ClusterConnectionSelectorTest
test_class.superclass: extends TestCase
test_case.body: @Test
  	public void testSelectConnection() throws Exception {
  		ClusterConnection conn = new ClusterConnection("test");
  		ClusterConnectionSelector selector = new ClusterConnectionSelector();
  		selector.setClusterConnectionHandler(new ClusterConnectionHandler() {
  
  			@Override
  			public int hashCodeForPacket(Packet packet) {
  				return packet.getStanzaFrom().hashCode();
  			}
  		});
  
  		Map<String,Object> props = new HashMap<>();
  		props.put(CLUSTER_SYS_CONNECTIONS_PER_NODE_PROP_KEY, 1);
  		selector.setProperties(props);
  		
  		Element el = new Element("iq", new String[] { "from" }, new String[] { "test1" });
  		Packet p = Packet.packetInstance(el);
  		assertNull(selector.selectConnection(p, conn));
  		
  		XMPPIOService<Object> serv1 = new XMPPIOService<Object>();
  		conn.addConn(serv1);
  		assertEquals(serv1, selector.selectConnection(p, conn));
  		
  		p.setPriority(Priority.SYSTEM);
  		assertEquals(serv1, selector.selectConnection(p, conn));
  
  		p.setPriority(null);
  		XMPPIOService<Object> serv2 = new XMPPIOService<Object>();
  		conn.addConn(serv2);
  		assertEquals(2, conn.size());
  		assertEquals(serv2, selector.selectConnection(p, conn));
  		
  		p.setPriority(Priority.SYSTEM);
  		assertEquals(serv1, selector.selectConnection(p, conn));
  
  		p.setPriority(null);
  		XMPPIOService<Object> serv3 = new XMPPIOService<Object>();
  		conn.addConn(serv3);
  		assertEquals(3, conn.size());
  		assertNotSame(serv1, selector.selectConnection(p, conn));
  		
  		p.setPriority(Priority.SYSTEM);
  		assertEquals(serv1, selector.selectConnection(p, conn));
  		
  		el = new Element("iq", new String[] { "from" }, new String[] { "test2" });
  		p = Packet.packetInstance(el);
  		assertEquals(3, conn.size());
  		assertNotSame(serv1, selector.selectConnection(p, conn));
  
  		el = new Element("iq", new String[] { "from" }, new String[] { "test3" });
  		p = Packet.packetInstance(el);
  		assertEquals(3, conn.size());
  		assertNotSame(serv1, selector.selectConnection(p, conn));
  
  		el = new Element("iq", new String[] { "from" }, new String[] { "test4" });
  		p = Packet.packetInstance(el);
  		assertEquals(3, conn.size());
  		assertNotSame(serv1, selector.selectConnection(p, conn));		
  	}
test_case.class_method_signature: ClusterConnectionSelectorTest.testSelectConnection()
test_case.full_signature: @Test public void testSelectConnection()
test_case.identifier: testSelectConnection
test_case.invocations: setClusterConnectionHandler hashCode getStanzaFrom put setProperties packetInstance assertNull selectConnection addConn assertEquals selectConnection setPriority assertEquals selectConnection setPriority addConn assertEquals size assertEquals selectConnection setPriority assertEquals selectConnection setPriority addConn assertEquals size assertNotSame selectConnection setPriority assertEquals selectConnection packetInstance assertEquals size assertNotSame selectConnection packetInstance assertEquals size assertNotSame selectConnection packetInstance assertEquals size assertNotSame selectConnection
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testSelectConnection()
focal_class.declarator: CLUSTER_SYS_CONNECTIONS_PER_NODE_PROP_KEY = "cluster-sys-connections-per-node"
focal_class.modifier: protected static final
focal_class.original_string: protected static final String CLUSTER_SYS_CONNECTIONS_PER_NODE_PROP_KEY = "cluster-sys-connections-per-node";
focal_class.type: String
focal_class.var_name: CLUSTER_SYS_CONNECTIONS_PER_NODE_PROP_KEY
focal_class.declarator: allConns = ClusterConnectionManager.CLUSTER_CONNECTIONS_PER_NODE_VAL
focal_class.modifier: private
focal_class.original_string: private int allConns = ClusterConnectionManager.CLUSTER_CONNECTIONS_PER_NODE_VAL;
focal_class.type: int
focal_class.var_name: allConns
focal_class.declarator: sysConns = 2
focal_class.modifier: private
focal_class.original_string: private int sysConns = 2;
focal_class.type: int
focal_class.var_name: sysConns
focal_class.declarator: handler
focal_class.modifier: private
focal_class.original_string: private ClusterConnectionHandler handler;
focal_class.type: ClusterConnectionHandler
focal_class.var_name: handler
focal_class.file: tigase-server 7.1.0/src/main/java/tigase/cluster/ClusterConnectionSelector.java
focal_class.identifier: ClusterConnectionSelector
focal_class.interfaces: implements ClusterConnectionSelectorIfc
focal_class.class_method_signature: ClusterConnectionSelector.selectConnection(Packet p, ClusterConnection conn)
focal_class.full_signature: @Override public XMPPIOService<Object> selectConnection(Packet p, ClusterConnection conn)
focal_class.identifier: selectConnection
focal_class.modifiers: @Override public
focal_class.parameters: (Packet p, ClusterConnection conn)
focal_class.return: XMPPIOService<Object>
focal_class.signature: XMPPIOService<Object> selectConnection(Packet p, ClusterConnection conn)
focal_class.class_method_signature: ClusterConnectionSelector.setClusterConnectionHandler(ClusterConnectionHandler handler)
focal_class.full_signature: @Override public void setClusterConnectionHandler(ClusterConnectionHandler handler)
focal_class.identifier: setClusterConnectionHandler
focal_class.modifiers: @Override public
focal_class.parameters: (ClusterConnectionHandler handler)
focal_class.return: void
focal_class.signature: void setClusterConnectionHandler(ClusterConnectionHandler handler)
focal_class.class_method_signature: ClusterConnectionSelector.setProperties(Map<String,Object> props)
focal_class.full_signature: @Override public void setProperties(Map<String,Object> props)
focal_class.identifier: setProperties
focal_class.modifiers: @Override public
focal_class.parameters: (Map<String,Object> props)
focal_class.return: void
focal_class.signature: void setProperties(Map<String,Object> props)
focal_method.body: @Override
  	public XMPPIOService<Object> selectConnection(Packet p, ClusterConnection conn) {
  		if (conn == null)
  			return null;
  		
  		int code  = Math.abs(handler.hashCodeForPacket(p));
  		List<XMPPIOService<Object>> conns = conn.getConnections();
  		if (conns.size() > 0) {
  			if (conns.size() > sysConns) {
  				if (p.getPriority() != null && p.getPriority().ordinal() <= Priority.CLUSTER.ordinal()) {
  					return conns.get(code % sysConns);
  				} else {
  					return conns.get(sysConns + (code % (conns.size() - sysConns)));
  				}
  			} else {
  				return conns.get(code % conns.size());
  			}
  		}
  		return null;		
  	}
focal_method.class_method_signature: ClusterConnectionSelector.selectConnection(Packet p, ClusterConnection conn)
focal_method.full_signature: @Override public XMPPIOService<Object> selectConnection(Packet p, ClusterConnection conn)
focal_method.identifier: selectConnection
focal_method.invocations: abs hashCodeForPacket getConnections size size getPriority ordinal getPriority ordinal get get size get size
focal_method.modifiers: @Override public
focal_method.parameters: (Packet p, ClusterConnection conn)
focal_method.return: XMPPIOService<Object>
focal_method.signature: XMPPIOService<Object> selectConnection(Packet p, ClusterConnection conn)