2012-10-16 07:28:54 +02:00
|
|
|
/*
|
|
|
|
* ProtocolLib - Bukkit server library that allows access to the Minecraft protocol.
|
|
|
|
* Copyright (C) 2012 Kristian S. Stangeland
|
|
|
|
*
|
2015-05-21 00:04:33 +02:00
|
|
|
* This program is free software; you can redistribute it and/or modify it under the terms of the
|
|
|
|
* GNU General Public License as published by the Free Software Foundation; either version 2 of
|
2012-10-16 07:28:54 +02:00
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
*
|
2015-05-21 00:04:33 +02:00
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
2012-10-16 07:28:54 +02:00
|
|
|
* See the GNU General Public License for more details.
|
|
|
|
*
|
2015-05-21 00:04:33 +02:00
|
|
|
* You should have received a copy of the GNU General Public License along with this program;
|
|
|
|
* if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
2012-10-16 07:28:54 +02:00
|
|
|
* 02111-1307 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
package com.comphenix.protocol;
|
|
|
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
import org.bukkit.plugin.Plugin;
|
|
|
|
|
|
|
|
import com.comphenix.protocol.async.AsyncListenerHandler;
|
2012-11-21 02:42:18 +01:00
|
|
|
import com.comphenix.protocol.async.AsyncMarker;
|
2012-10-29 04:17:53 +01:00
|
|
|
import com.comphenix.protocol.error.ErrorReporter;
|
2012-10-16 07:28:54 +02:00
|
|
|
import com.comphenix.protocol.events.PacketEvent;
|
|
|
|
import com.comphenix.protocol.events.PacketListener;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Represents a asynchronous packet handler.
|
|
|
|
*
|
|
|
|
* @author Kristian
|
|
|
|
*/
|
|
|
|
public interface AsynchronousManager {
|
|
|
|
/**
|
|
|
|
* Registers an asynchronous packet handler.
|
|
|
|
* <p>
|
2012-11-21 02:42:18 +01:00
|
|
|
* Use {@link AsyncMarker#incrementProcessingDelay()} to delay a packet until its ready to be transmitted.
|
|
|
|
* <p>
|
2012-10-16 07:28:54 +02:00
|
|
|
* To start listening asynchronously, pass the getListenerLoop() runnable to a different thread.
|
2013-12-05 21:24:31 +01:00
|
|
|
* @param listener - the packet listener that will receive these asynchronous events.
|
|
|
|
* @return An asynchronous handler.
|
2012-10-16 07:28:54 +02:00
|
|
|
*/
|
2020-06-06 21:13:29 +02:00
|
|
|
AsyncListenerHandler registerAsyncHandler(PacketListener listener);
|
2012-10-16 07:28:54 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Unregisters and closes the given asynchronous handler.
|
|
|
|
* @param handler - asynchronous handler.
|
|
|
|
*/
|
2020-06-06 21:13:29 +02:00
|
|
|
void unregisterAsyncHandler(AsyncListenerHandler handler);
|
2012-10-16 07:28:54 +02:00
|
|
|
|
2014-07-26 17:28:05 +02:00
|
|
|
/**
|
|
|
|
* Unregisters and closes the first asynchronous handler associated with the given listener.
|
2015-05-21 00:04:33 +02:00
|
|
|
* @param listener - asynchronous listener
|
2014-07-26 17:28:05 +02:00
|
|
|
*/
|
2020-06-06 21:13:29 +02:00
|
|
|
void unregisterAsyncHandler(PacketListener listener);
|
2014-07-26 17:28:05 +02:00
|
|
|
|
2012-10-16 07:28:54 +02:00
|
|
|
/**
|
|
|
|
* Unregisters every asynchronous handler associated with this plugin.
|
|
|
|
* @param plugin - the original plugin.
|
|
|
|
*/
|
2020-06-06 21:13:29 +02:00
|
|
|
void unregisterAsyncHandlers(Plugin plugin);
|
2012-10-16 07:28:54 +02:00
|
|
|
|
2013-12-05 06:52:20 +01:00
|
|
|
/**
|
2015-05-21 00:04:33 +02:00
|
|
|
* Retrieves a immutable set containing the types of the sent server packets that will be
|
2013-12-05 06:52:20 +01:00
|
|
|
* observed by the asynchronous listeners.
|
|
|
|
* @return Every filtered server packet.
|
|
|
|
*/
|
2020-06-06 21:13:29 +02:00
|
|
|
Set<PacketType> getSendingTypes();
|
|
|
|
|
2013-12-05 06:52:20 +01:00
|
|
|
/**
|
2013-12-05 21:24:31 +01:00
|
|
|
* Retrieves a immutable set containing the types of the received client packets that will be
|
2013-12-05 06:52:20 +01:00
|
|
|
* observed by the asynchronous listeners.
|
|
|
|
* @return Every filtered client packet.
|
|
|
|
*/
|
2020-06-06 21:13:29 +02:00
|
|
|
Set<PacketType> getReceivingTypes();
|
2012-10-16 07:28:54 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Determine if a given synchronous packet has asynchronous listeners.
|
|
|
|
* @param packet - packet to test.
|
|
|
|
* @return TRUE if it does, FALSE otherwise.
|
|
|
|
*/
|
2020-06-06 21:13:29 +02:00
|
|
|
boolean hasAsynchronousListeners(PacketEvent packet);
|
2012-10-16 07:28:54 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve the default packet stream.
|
|
|
|
* @return Default packet stream.
|
|
|
|
*/
|
2020-06-06 21:13:29 +02:00
|
|
|
PacketStream getPacketStream();
|
2012-10-16 07:28:54 +02:00
|
|
|
|
|
|
|
/**
|
2012-10-29 04:17:53 +01:00
|
|
|
* Retrieve the default error reporter.
|
|
|
|
* @return Default reporter.
|
2012-10-16 07:28:54 +02:00
|
|
|
*/
|
2020-06-06 21:13:29 +02:00
|
|
|
ErrorReporter getErrorReporter();
|
2012-10-16 07:28:54 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove listeners, close threads and transmit every delayed packet.
|
|
|
|
*/
|
2020-06-06 21:13:29 +02:00
|
|
|
void cleanupAll();
|
2012-10-16 07:28:54 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Signal that a packet is ready to be transmitted.
|
|
|
|
* <p>
|
|
|
|
* This should only be called if {@link com.comphenix.protocol.async.AsyncMarker#incrementProcessingDelay() AsyncMarker.incrementProcessingDelay()}
|
|
|
|
* has been called previously.
|
|
|
|
* @param packet - packet to signal.
|
|
|
|
*/
|
2020-06-06 21:13:29 +02:00
|
|
|
void signalPacketTransmission(PacketEvent packet);
|
2012-11-04 01:10:05 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Register a synchronous listener that handles packets when they time out.
|
|
|
|
* @param listener - synchronous listener that will handle timed out packets.
|
|
|
|
*/
|
2020-06-06 21:13:29 +02:00
|
|
|
void registerTimeoutHandler(PacketListener listener);
|
2012-11-04 01:10:05 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Unregisters a given timeout listener.
|
|
|
|
* @param listener - the timeout listener to unregister.
|
|
|
|
*/
|
2020-06-06 21:13:29 +02:00
|
|
|
void unregisterTimeoutHandler(PacketListener listener);
|
2012-11-04 01:10:05 +01:00
|
|
|
|
|
|
|
/**
|
2014-03-13 23:55:33 +01:00
|
|
|
* Get a immutable set of every registered timeout handler.
|
|
|
|
* @return Set of every registered timeout handler.
|
2012-11-04 01:10:05 +01:00
|
|
|
*/
|
2020-06-06 21:13:29 +02:00
|
|
|
Set<PacketListener> getTimeoutHandlers();
|
2014-03-13 23:55:33 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get an immutable set of every registered asynchronous packet listener.
|
|
|
|
* @return Set of every asynchronous packet listener.
|
|
|
|
*/
|
2020-06-06 21:13:29 +02:00
|
|
|
Set<PacketListener> getAsyncHandlers();
|
2016-05-21 23:37:13 +02:00
|
|
|
}
|