Package com.davfx.ninio.common

Examples of com.davfx.ninio.common.ReadyFactory


  public void connect(final PingClientHandler clientHandler) {
    final Queue q;
    final ScheduledExecutorService re;
    final boolean shouldCloseQueue;
   
    final ReadyFactory rf;
    final InternalPingServerReadyFactory readyFactoryToClose;
    if (readyFactory == null) {
      readyFactoryToClose = new InternalPingServerReadyFactory();
      rf = readyFactoryToClose;
    } else {
      rf = readyFactory;
      readyFactoryToClose = null;
    }
   
    if (queue == null) {
      try {
        q = new Queue();
      } catch (IOException e) {
        clientHandler.failed(e);
        return;
      }
      re = Executors.newSingleThreadScheduledExecutor();
      shouldCloseQueue = true;
    } else {
      q = queue;
      re = repeatExecutor;
      shouldCloseQueue = false;
    }

    final Address a;
    if (host != null) {
      if (port < 0) {
        a = new Address(host, address.getPort());
      } else {
        a = new Address(host, port);
      }
    } else {
      a = address;
    }
   
    final Set<InstanceMapper> instanceMappers = new HashSet<>();
    re.scheduleAtFixedRate(new Runnable() {
      @Override
      public void run() {
        q.post(new Runnable() {
          @Override
          public void run() {
            Date now = new Date();
            for (InstanceMapper i : instanceMappers) {
              i.repeat(now, minTimeToRepeat, timeoutFromBeginning);
            }
           
            Iterator<InstanceMapper> ii = instanceMappers.iterator();
            while (ii.hasNext()) {
              InstanceMapper i = ii.next();
              if (i.instances.isEmpty()) {
                ii.remove();
              }
            }
          }
        });
      }
    }, 0, (long) (repeatTime * 1000d), TimeUnit.MILLISECONDS);

    q.post(new Runnable() {
      @Override
      public void run() {
        ByteBufferAllocator allocator = new OnceByteBufferAllocator();
        Ready ready = rf.create(q, allocator);
       
        ready.connect(a, new ReadyConnection() {
          private final InstanceMapper instanceMapper = new InstanceMapper();

          @Override
View Full Code Here


                            connection.second.close();
                          }
                        }
                      } else if (len == 0) {
                        Address address = new Address(in.readUTF(), in.readInt());
                        ReadyFactory factory = proxyUtils.read(in);
                        Ready r = factory.create(queue, new OnceByteBufferAllocator());
                        final MutablePair<Address, CloseableByteBufferHandler> connection = new MutablePair<Address, CloseableByteBufferHandler>(address, null);
                        connections.put(connectionId, connection);
                       
                        final Lock lock = new Lock();
                       
View Full Code Here

                            connection.second.close();
                          }
                        }
                      } else if (len == 0) {
                        Address address = new Address(in.readUTF(), in.readInt());
                        ReadyFactory factory = proxyUtils.read(in);
                        Ready r = factory.create(queue, new OnceByteBufferAllocator());
                        MutablePair<Address, CloseableByteBufferHandler> connection = new MutablePair<Address, CloseableByteBufferHandler>(address, null);
                        connections.put(connectionId, connection);
                       
                        Lock lock = new Lock();
                       
View Full Code Here

  public void connect(PingClientHandler clientHandler) {
    Queue q;
    ScheduledExecutorService re;
    boolean shouldCloseQueue;
   
    ReadyFactory rf;
    InternalPingServerReadyFactory readyFactoryToClose;
    if (readyFactory == null) {
      readyFactoryToClose = new InternalPingServerReadyFactory();
      rf = readyFactoryToClose;
    } else {
      rf = readyFactory;
      readyFactoryToClose = null;
    }
   
    if (queue == null) {
      try {
        q = new Queue();
      } catch (IOException e) {
        clientHandler.failed(e);
        return;
      }
      re = Executors.newSingleThreadScheduledExecutor();
      shouldCloseQueue = true;
    } else {
      q = queue;
      re = repeatExecutor;
      shouldCloseQueue = false;
    }

    final Address a;
    if (host != null) {
      if (port < 0) {
        a = new Address(host, address.getPort());
      } else {
        a = new Address(host, port);
      }
    } else {
      a = address;
    }
   
    final Set<InstanceMapper> instanceMappers = new HashSet<>();
    re.scheduleAtFixedRate(new Runnable() {
      @Override
      public void run() {
        q.post(new Runnable() {
          @Override
          public void run() {
            Date now = new Date();
            for (InstanceMapper i : instanceMappers) {
              i.repeat(now, minTimeToRepeat, timeoutFromBeginning);
            }
           
            Iterator<InstanceMapper> ii = instanceMappers.iterator();
            while (ii.hasNext()) {
              InstanceMapper i = ii.next();
              if (i.instances.isEmpty()) {
                ii.remove();
              }
            }
          }
        });
      }
    }, 0, (long) (repeatTime * 1000d), TimeUnit.MILLISECONDS);

    q.post(new Runnable() {
      @Override
      public void run() {
        ByteBufferAllocator allocator = new OnceByteBufferAllocator();
        Ready ready = rf.create(q, allocator);
       
        ready.connect(a, new ReadyConnection() {
          private final InstanceMapper instanceMapper = new InstanceMapper();

          @Override
View Full Code Here

TOP

Related Classes of com.davfx.ninio.common.ReadyFactory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.