001/*
002 *  Licensed to the Apache Software Foundation (ASF) under one
003 *  or more contributor license agreements.  See the NOTICE file
004 *  distributed with this work for additional information
005 *  regarding copyright ownership.  The ASF licenses this file
006 *  to you under the Apache License, Version 2.0 (the
007 *  "License"); you may not use this file except in compliance
008 *  with the License.  You may obtain a copy of the License at
009 *
010 *    http://www.apache.org/licenses/LICENSE-2.0
011 *
012 *  Unless required by applicable law or agreed to in writing,
013 *  software distributed under the License is distributed on an
014 *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 *  KIND, either express or implied.  See the License for the
016 *  specific language governing permissions and limitations
017 *  under the License.
018 *
019 */
020package org.apache.mina.core.future;
021
022import org.apache.mina.core.session.IoSession;
023
024/**
025 * A default implementation of {@link CloseFuture}.
026 *
027 * @author <a href="http://mina.apache.org">Apache MINA Project</a>
028 */
029public class DefaultCloseFuture extends DefaultIoFuture implements CloseFuture {
030    /**
031     * Creates a new instance.
032     * 
033     * @param session The associated session
034     */
035    public DefaultCloseFuture(IoSession session) {
036        super(session);
037    }
038
039    /**
040     * {@inheritDoc}
041     */
042    public boolean isClosed() {
043        if (isDone()) {
044            return ((Boolean) getValue()).booleanValue();
045        } else {
046            return false;
047        }
048    }
049
050    /**
051     * {@inheritDoc}
052     */
053    public void setClosed() {
054        setValue(Boolean.TRUE);
055    }
056
057    /**
058     * {@inheritDoc}
059     */
060    @Override
061    public CloseFuture await() throws InterruptedException {
062        return (CloseFuture) super.await();
063    }
064
065    /**
066     * {@inheritDoc}
067     */
068    @Override
069    public CloseFuture awaitUninterruptibly() {
070        return (CloseFuture) super.awaitUninterruptibly();
071    }
072
073    /**
074     * {@inheritDoc}
075     */
076    @Override
077    public CloseFuture addListener(IoFutureListener<?> listener) {
078        return (CloseFuture) super.addListener(listener);
079    }
080
081    /**
082     * {@inheritDoc}
083     */
084    @Override
085    public CloseFuture removeListener(IoFutureListener<?> listener) {
086        return (CloseFuture) super.removeListener(listener);
087    }
088}