All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jgroups.tests.bla Maven / Gradle / Ivy

Go to download

This artifact provides a single jar that contains all classes required to use remote Jakarta Enterprise Beans and Jakarta Messaging, including all dependencies. It is intended for use by those not using maven, maven users should just import the Jakarta Enterprise Beans and Jakarta Messaging BOM's instead (shaded JAR's cause lots of problems with maven, as it is very easy to inadvertently end up with different versions on classes on the class path).

There is a newer version: 35.0.0.Beta1
Show newest version
package org.jgroups.tests;

import org.jgroups.util.Util;

import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import java.util.Iterator;

/**
 * @author Bela Ban
 * @since x.y
 */
public class bla implements Runnable {
    protected ServerSocketChannel ch;
    protected Selector selector;
    protected volatile boolean running;

    protected void start() throws IOException {
        ch=ServerSocketChannel.open();
        ch.bind(new InetSocketAddress(InetAddress.getLoopbackAddress(), 7500));
        ch.configureBlocking(false);
        selector=Selector.open();
        ch.register(selector, SelectionKey.OP_ACCEPT, null);
        running=true;

        new Thread(this).start();

        while(running) {
            selector.select();
            Iterator it=selector.selectedKeys().iterator();
            while(it.hasNext()) {
                SelectionKey key=it.next();
                it.remove();
                System.out.printf("selection key: %s\n", key);
                if(key.isAcceptable()) {
                    SocketChannel client_sock=ch.accept();
                    Util.close(client_sock);
                }
            }
        }
        Util.close(selector, ch);
    }

    public void run() {
        Util.sleep(5000);
        running=false;
        System.out.printf("--set running=%b, waking up selector\n", running);
        selector.wakeup();
    }

    public static void main(String[] args) throws Exception {
        new bla().start();


    }


}







© 2015 - 2025 Weber Informatics LLC | Privacy Policy