001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
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    }