Package org.apache.sshd.common.future

Examples of org.apache.sshd.common.future.DefaultCloseFuture


            notifyStateChanged();
        }
    }

    protected CloseFuture preClose(boolean immediately) {
        CloseFuture future = new DefaultCloseFuture(lock);
        future.setClosed();
        return future;
    }
View Full Code Here


            }
            public boolean isClosed() {
                return !session.isConnected();
            }
            public org.apache.sshd.common.future.CloseFuture close(boolean immediately) {
                final DefaultCloseFuture future = new DefaultCloseFuture(lock);
                session.close(false).addListener(new IoFutureListener<IoFuture>() {
                    public void operationComplete(IoFuture f) {
                        future.setValue(true);
                    }
                });
                return future;
            }
        };
View Full Code Here

* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
public class CloseableUtils {

    public static CloseFuture closed() {
        CloseFuture future = new DefaultCloseFuture(null);
        future.setClosed();
        return future;
    }
View Full Code Here

                nbNonNulls++;
            }
        }
        if (nbNonNulls == 0) {
            return new Closeable() {
                final CloseFuture future = new DefaultCloseFuture(lock);
                public boolean isClosed() {
                    return future.isClosed();
                }
                public boolean isClosing() {
                    return isClosed();
                }
                public CloseFuture close(boolean immediately) {
                    future.setClosed();
                    return future;
                }
            };
        } else if (nbNonNulls == 1) {
            for (Closeable closeable : closeables) {
                if (closeable != null) {
                    return closeable;
                }
            }
            throw new IllegalStateException();
        } else {
            return new Closeable() {
                final CloseFuture future = new DefaultCloseFuture(lock);
                final AtomicBoolean closing = new AtomicBoolean();
                public boolean isClosed() {
                    return future.isClosed();
                }
                public boolean isClosing() {
                    return closing.get();
                }
                public CloseFuture close(boolean immediately) {
                    final AtomicInteger count = new AtomicInteger(closeables.length);
                    if (closing.compareAndSet(false, true)) {
                        SshFutureListener<CloseFuture> listener = new SshFutureListener<CloseFuture>() {
                            public void operationComplete(CloseFuture f) {
                                if (count.decrementAndGet() == 0) {
                                    future.setClosed();
                                }
                            }
                        };
                        for (Closeable c : closeables) {
                            if (c != null) {
View Full Code Here

                nbNonNulls++;
            }
        }
        if (nbNonNulls == 0) {
            return new Closeable() {
                final CloseFuture future = new DefaultCloseFuture(lock);
                public boolean isClosed() {
                    return future.isClosed();
                }
                public boolean isClosing() {
                    return isClosed();
                }
                public CloseFuture close(boolean immediately) {
                    future.setClosed();
                    return future;
                }
            };
        } else if (nbNonNulls == 1) {
            for (Closeable closeable : closeables) {
                if (closeable != null) {
                    return closeable;
                }
            }
            throw new IllegalStateException();
        } else {
            return new Closeable() {
                final DefaultCloseFuture future = new DefaultCloseFuture(lock);
                final AtomicBoolean closing = new AtomicBoolean();
                public boolean isClosed() {
                    return future.isClosed();
                }
                public boolean isClosing() {
                    return closing.get();
                }
                public CloseFuture close(final boolean immediately) {
                    if (closing.compareAndSet(false, true)) {
                        final Iterator<Closeable> iterator = Arrays.asList(closeables).iterator();
                        SshFutureListener<CloseFuture> listener = new SshFutureListener<CloseFuture>() {
                            public void operationComplete(CloseFuture previousFuture) {
                                while (iterator.hasNext()) {
                                    Closeable c = iterator.next();
                                    if (c != null) {
                                        CloseFuture nextFuture = c.close(immediately);
                                        nextFuture.addListener(this);
                                        return;
                                    }
                                }
                                if (!iterator.hasNext()) {
                                    future.setClosed();
                                }
                            }
                        };
                        listener.operationComplete(null);
                    }
View Full Code Here

    public static <T extends SshFuture> CloseFuture parallel(final SshFuture<T>... futures) {
        return parallel(null, futures);
    }

    public static <T extends SshFuture> CloseFuture parallel(Object lock, final SshFuture<T>... futures) {
        final CloseFuture future = new DefaultCloseFuture(lock);
        if (futures.length > 0) {
            final AtomicInteger count = new AtomicInteger(futures.length);
            SshFutureListener<T> listener = new SshFutureListener<T>() {
                public void operationComplete(T f) {
                    if (count.decrementAndGet() == 0) {
                        future.setClosed();
                    }
                }
            };
            for (SshFuture<T> f : futures) {
                if (f != null) {
                    f.addListener(listener);
                } else {
                    listener.operationComplete(null);
                }
            }
        } else {
            future.setClosed();
        }
        return future;
    }
View Full Code Here

            this(new Object());
        }

        protected AbstractCloseable(Object lock) {
            this.lock = lock;
            this.closeFuture = new DefaultCloseFuture(lock);
        }
View Full Code Here

* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
public class CloseableUtils {

    public static CloseFuture closed() {
        CloseFuture future = new DefaultCloseFuture(null);
        future.setClosed();
        return future;
    }
View Full Code Here

    public static Closeable parallel(final Object lock, final Closeable... closeables) {
        if (closeables.length == 0) {
            return new Closeable() {
                public CloseFuture close(boolean immediately) {
                    final CloseFuture future = new DefaultCloseFuture(lock);
                    future.setClosed();
                    return future;
                }
            };
        } else if (closeables.length == 1) {
            return closeables[0];
        } else {
            return new Closeable() {
                public CloseFuture close(boolean immediately) {
                    final CloseFuture future = new DefaultCloseFuture(lock);
                    final AtomicInteger count = new AtomicInteger(closeables.length);
                    SshFutureListener<CloseFuture> listener = new SshFutureListener<CloseFuture>() {
                        public void operationComplete(CloseFuture f) {
                            if (count.decrementAndGet() == 0) {
                                future.setClosed();
                            }
                        }
                    };
                    for (Closeable c : closeables) {
                        c.close(immediately).addListener(listener);
View Full Code Here

    @Override
    protected Closeable getInnerCloseable() {
        return new Closeable() {
            public org.apache.sshd.common.future.CloseFuture close(boolean immediately) {
                final DefaultCloseFuture future = new DefaultCloseFuture(lock);
                session.close(false).addListener(new IoFutureListener<IoFuture>() {
                    public void operationComplete(IoFuture f) {
                        future.setValue(true);
                    }
                });
                return future;
            }
        };
View Full Code Here

TOP

Related Classes of org.apache.sshd.common.future.DefaultCloseFuture

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.