001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.kernel.nio.intraband;
016    
017    import com.liferay.portal.kernel.nio.intraband.CompletionHandler.CompletionType;
018    
019    import java.io.IOException;
020    
021    import java.nio.channels.Channel;
022    import java.nio.channels.GatheringByteChannel;
023    import java.nio.channels.ScatteringByteChannel;
024    
025    import java.util.EnumSet;
026    import java.util.concurrent.TimeUnit;
027    import java.util.concurrent.TimeoutException;
028    
029    /**
030     * @author Shuyang Zhou
031     */
032    public interface Intraband {
033    
034            public void close() throws InterruptedException, IOException;
035    
036            public DatagramReceiveHandler[] getDatagramReceiveHandlers();
037    
038            public boolean isOpen();
039    
040            public RegistrationReference registerChannel(Channel channel)
041                    throws IOException;
042    
043            public RegistrationReference registerChannel(
044                            ScatteringByteChannel scatteringByteChannel,
045                            GatheringByteChannel gatheringByteChannel)
046                    throws IOException;
047    
048            public DatagramReceiveHandler registerDatagramReceiveHandler(
049                    byte type, DatagramReceiveHandler datagramReceiveHandler);
050    
051            public void sendDatagram(
052                    RegistrationReference registrationReference, Datagram datagram);
053    
054            public <A> void sendDatagram(
055                    RegistrationReference registrationReference, Datagram datagram,
056                    A attachment, EnumSet<CompletionType> completionTypes,
057                    CompletionHandler<A> completionHandler);
058    
059            public <A> void sendDatagram(
060                    RegistrationReference registrationReference, Datagram datagram,
061                    A attachment, EnumSet<CompletionType> completionTypes,
062                    CompletionHandler<A> completionHandler, long timeout,
063                    TimeUnit timeUnit);
064    
065            public Datagram sendSyncDatagram(
066                            RegistrationReference registrationReference, Datagram datagram)
067                    throws InterruptedException, IOException, TimeoutException;
068    
069            public Datagram sendSyncDatagram(
070                            RegistrationReference registrationReference, Datagram datagram,
071                            long timeout, TimeUnit timeUnit)
072                    throws InterruptedException, IOException, TimeoutException;
073    
074            public DatagramReceiveHandler unregisterDatagramReceiveHandler(byte type);
075    
076    }