Search in sources :

Example 1 with FirewallingConnectionManager

use of com.hazelcast.nio.tcp.FirewallingConnectionManager in project hazelcast-jet by hazelcast.

the class JetSplitBrainTestSupport method createHazelcastInstanceInBrain.

/**
 * Starts a new {@code JetInstance} which is only able to communicate
 * with members on one of the two brains.
 * @param firstSubCluster jet instances in the first sub cluster
 * @param secondSubCluster jet instances in the first sub cluster
 * @param createOnFirstSubCluster if true, new instance is created on the first sub cluster.
 * @return a HazelcastInstance whose {@code MockJoiner} has blacklisted the other brain's
 *         members and its connection manager blocks connections to other brain's members
 * @see TestHazelcastInstanceFactory#newHazelcastInstance(Address, com.hazelcast.config.Config, Address[])
 */
protected final JetInstance createHazelcastInstanceInBrain(JetInstance[] firstSubCluster, JetInstance[] secondSubCluster, boolean createOnFirstSubCluster) {
    Address newMemberAddress = nextAddress();
    JetInstance[] instancesToBlock = createOnFirstSubCluster ? secondSubCluster : firstSubCluster;
    List<Address> addressesToBlock = new ArrayList<>(instancesToBlock.length);
    for (JetInstance anInstancesToBlock : instancesToBlock) {
        if (isInstanceActive(anInstancesToBlock)) {
            addressesToBlock.add(getAddress(anInstancesToBlock.getHazelcastInstance()));
            // block communication from these instances to the new address
            FirewallingConnectionManager connectionManager = getFireWalledConnectionManager(anInstancesToBlock.getHazelcastInstance());
            connectionManager.blockNewConnection(newMemberAddress);
            connectionManager.closeActiveConnection(newMemberAddress);
        }
    }
    // indicate we need to unblacklist addresses from joiner when split-brain will be healed
    unblacklistHint = true;
    // create a new Hazelcast instance which has blocked addresses blacklisted in its joiner
    return createJetMember(createConfig(), addressesToBlock.toArray(new Address[addressesToBlock.size()]));
}
Also used : Address(com.hazelcast.nio.Address) FirewallingConnectionManager(com.hazelcast.nio.tcp.FirewallingConnectionManager) JetInstance(com.hazelcast.jet.JetInstance) ArrayList(java.util.ArrayList)

Aggregations

JetInstance (com.hazelcast.jet.JetInstance)1 Address (com.hazelcast.nio.Address)1 FirewallingConnectionManager (com.hazelcast.nio.tcp.FirewallingConnectionManager)1 ArrayList (java.util.ArrayList)1