本文整理汇总了Java中org.apache.mina.transport.socket.nio.SocketAcceptor类的典型用法代码示例。如果您正苦于以下问题:Java SocketAcceptor类的具体用法?Java SocketAcceptor怎么用?Java SocketAcceptor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SocketAcceptor类属于org.apache.mina.transport.socket.nio包,在下文中一共展示了SocketAcceptor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run_startup_configurations
import org.apache.mina.transport.socket.nio.SocketAcceptor; //导入依赖的package包/类
public static void run_startup_configurations() {
ip = ServerConfig.IP_ADDRESS + ":" + PORT;
ByteBuffer.setUseDirectBuffers(false);
ByteBuffer.setAllocator(new SimpleByteBufferAllocator());
acceptor = new SocketAcceptor();
final SocketAcceptorConfig cfg = new SocketAcceptorConfig();
cfg.getSessionConfig().setTcpNoDelay(true);
cfg.setDisconnectOnUnbind(true);
cfg.getFilterChain().addLast("codec", new ProtocolCodecFilter(new MapleCodecFactory()));
players = new PlayerStorage(-10);
try {
InetSocketadd = new InetSocketAddress(PORT);
acceptor.bind(InetSocketadd, new MapleServerHandler(), cfg);
System.out.println("Cash Shop Server is listening on port " + PORT + ".");
} catch (final IOException e) {
System.out.println(" Failed!");
System.err.println("Could not bind to port " + PORT + ".");
throw new RuntimeException("Binding failed.", e);
}
}
示例2: run_startup_configurations
import org.apache.mina.transport.socket.nio.SocketAcceptor; //导入依赖的package包/类
public static final void run_startup_configurations() {
userLimit = ServerConfig.USER_LIMIT;
serverName = ServerConfig.SERVER_NAME;
eventMessage = ServerConfig.EVENT_MSG;
maxCharacters = ServerConfig.MAX_CHARACTERS;
ByteBuffer.setUseDirectBuffers(false);
ByteBuffer.setAllocator(new SimpleByteBufferAllocator());
acceptor = new SocketAcceptor();
final SocketAcceptorConfig cfg = new SocketAcceptorConfig();
cfg.getSessionConfig().setTcpNoDelay(true);
cfg.setDisconnectOnUnbind(true);
cfg.getFilterChain().addLast("codec", new ProtocolCodecFilter(new MapleCodecFactory()));
try {
InetSocketadd = new InetSocketAddress(8484);
acceptor.bind(InetSocketadd, new MapleServerHandler(), cfg);
System.out.println("Login Server is listening on port 8484.");
} catch (IOException e) {
System.out.println(" Failed!");
System.err.println("Could not bind to port 8484: " + e);
}
}
示例3: main
import org.apache.mina.transport.socket.nio.SocketAcceptor; //导入依赖的package包/类
public static void main(String[] args) throws Exception{
int port=9527;
final IoAcceptor acceptor=new SocketAcceptor(Runtime.getRuntime().availableProcessors() + 1,
Executors.newCachedThreadPool());
acceptor.getFilterChain().addLast("stringserialize", new ProtocolCodecFilter(new ObjectSerializationCodecFactory()));
IoHandler handler=new IoHandlerAdapter(){
public void messageReceived(IoSession session, Object message)
throws Exception {
if("quit".equalsIgnoreCase(message.toString())){
acceptor.unbindAll();
System.out.println("Server has been shutdown!");
System.exit(0);
}
System.out.println("Message from client: "+message);
session.write("Server response��"+message);
}
};
acceptor.bind(new InetSocketAddress(port), handler);
System.out.println("Server listen on port: "+port);
}
示例4: start
import org.apache.mina.transport.socket.nio.SocketAcceptor; //导入依赖的package包/类
/** */
@PostConstruct
public void start() throws IOException
{
if (this.acceptor != null)
throw new IllegalStateException("TcpTableService already running");
InetAddress binding = null;
String bindAddress = System.getProperty("jboss.bind.address");
if (bindAddress != null && !"0.0.0.0".equals(bindAddress))
binding = InetAddress.getByName(bindAddress);
log.log(Level.INFO,"Starting TcpTableService: {0}:{1}", new Object[]{(binding==null ? "*" : binding),port});
this.acceptor = new SocketAcceptor();
this.acceptor.getFilterChain().addLast(
"codec",
new ProtocolCodecFilter(
new TextLineCodecFactory(Charset.forName("UTF-8"))));
this.acceptor.bind(new InetSocketAddress(binding, this.port), new Handler());
}
示例5: run_startup_configurations
import org.apache.mina.transport.socket.nio.SocketAcceptor; //导入依赖的package包/类
public static void run_startup_configurations() {
System.out.print("Loading Cash Shop...");
ip = ServerConfig.interface_ + ":" + PORT;
ByteBuffer.setUseDirectBuffers(false);
ByteBuffer.setAllocator(new SimpleByteBufferAllocator());
acceptor = new SocketAcceptor();
final SocketAcceptorConfig cfg = new SocketAcceptorConfig();
cfg.getSessionConfig().setTcpNoDelay(true);
cfg.setDisconnectOnUnbind(true);
cfg.getFilterChain().addLast("codec", new ProtocolCodecFilter(new MapleCodecFactory()));
players = new PlayerStorage(-10);
try {
InetSocketadd = new InetSocketAddress(PORT);
acceptor.bind(InetSocketadd, new MapleServerHandler(), cfg);
System.out.println(" Complete!");
System.out.println("Cash Shop Server is listening on port " + PORT + ".");
} catch (final IOException e) {
System.out.println(" Failed!");
System.err.println("Could not bind to port " + PORT + ".");
throw new RuntimeException("Binding failed.", e);
}
}
示例6: run_startup_configurations
import org.apache.mina.transport.socket.nio.SocketAcceptor; //导入依赖的package包/类
public static void run_startup_configurations() {
ip = ServerConfig.interface_ + ":" + PORT;
ByteBuffer.setUseDirectBuffers(false);
ByteBuffer.setAllocator(new SimpleByteBufferAllocator());
acceptor = new SocketAcceptor();
SocketAcceptorConfig cfg = new SocketAcceptorConfig();
cfg.getSessionConfig().setTcpNoDelay(true);
cfg.setDisconnectOnUnbind(true);
cfg.getFilterChain().addLast("codec", new ProtocolCodecFilter(new MapleCodecFactory()));
players = new PlayerStorage(-30);
try {
InetSocketadd = new InetSocketAddress(8601);
acceptor.bind(InetSocketadd, new MapleServerHandler(), cfg);
System.out.println("Farm Server is listening on port 8601.");
} catch (IOException e) {
System.err.println("Binding to port 8601 failed");
throw new RuntimeException("Binding failed.", e);
}
}
示例7: close
import org.apache.mina.transport.socket.nio.SocketAcceptor; //导入依赖的package包/类
public synchronized void close ()
{
if (closing)
return;
closing = true;
for (Link link : links)
link.close ();
links.clear ();
SocketAcceptor socketAcceptor = router.socketAcceptor ();
for (InetSocketAddress address : listenAddresses)
{
// wait for pending messages to be written
// todo check that this really flushes messages
for (IoSession session : socketAcceptor.getManagedSessions (address))
session.close ().join (10000);
socketAcceptor.unbind (address);
}
}
示例8: doOpen
import org.apache.mina.transport.socket.nio.SocketAcceptor; //导入依赖的package包/类
@Override
protected void doOpen() throws Throwable {
// set thread pool.
acceptor = new SocketAcceptor(getUrl().getPositiveParameter(Constants.IO_THREADS_KEY, Constants.DEFAULT_IO_THREADS),
Executors.newCachedThreadPool(new NamedThreadFactory("MinaServerWorker",
true)));
// config
SocketAcceptorConfig cfg = (SocketAcceptorConfig) acceptor.getDefaultConfig();
cfg.setThreadModel(ThreadModel.MANUAL);
// set codec.
acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new MinaCodecAdapter(getCodec(), getUrl(), this)));
acceptor.bind(getBindAddress(), new MinaHandler(getUrl(), this));
}
示例9: start
import org.apache.mina.transport.socket.nio.SocketAcceptor; //导入依赖的package包/类
public void start() throws Exception {
acceptor = new SocketAcceptor();
// Prepare the configuration
SocketAcceptorConfig cfg = new SocketAcceptorConfig();
cfg.setReuseAddress(true);
Charset charset = Charset.forName("UTF-8");
cfg.getFilterChain().addLast("codec", new ProtocolCodecFilter(new TextLineCodecFactory(charset)));
// Bind
acceptor.bind(new InetSocketAddress(port), new ReverseProtocolHandler(), cfg);
}
示例10: CoreThreadPool
import org.apache.mina.transport.socket.nio.SocketAcceptor; //导入依赖的package包/类
/**
* Create a new thread pool monitor mbean, giving it the pool to attach to.
*
* @param acceptor
* The pool to attach to.
*/
public CoreThreadPool(final SocketAcceptor acceptor) {
if (acceptor == null) {
throw new NullPointerException("acceptor is null");
}
//ExecutorThreadModel threadModel = (ExecutorThreadModel) acceptor.getDefaultConfig().getThreadModel();
//this.executor = (ThreadPoolExecutor) threadModel.getExecutor();
final ExecutorFilter executorFilter = (ExecutorFilter) acceptor.getFilterChain().get(EXECUTOR_FILTER_NAME);
this.executor = (ThreadPoolExecutor) executorFilter.getExecutor();
this.mina = new MINAStatCollector(acceptor);
}
示例11: initializePlugin
import org.apache.mina.transport.socket.nio.SocketAcceptor; //导入依赖的package包/类
public void initializePlugin(PluginManager manager, File pluginDirectory) {
// Add filter to filter chain builder
ConnectionManagerImpl connManager = (ConnectionManagerImpl) XMPPServer.getInstance().getConnectionManager();
defaultPortFilter = new RawPrintFilter("C2S");
SocketAcceptor socketAcceptor = connManager.getSocketAcceptor();
if (socketAcceptor != null) {
socketAcceptor.getFilterChain().addBefore("xmpp", "rawDebugger", defaultPortFilter);
}
oldPortFilter = new RawPrintFilter("SSL");
SocketAcceptor sslAcceptor = connManager.getSSLSocketAcceptor();
if (sslAcceptor != null) {
sslAcceptor.getFilterChain().addBefore("xmpp", "rawDebugger", oldPortFilter);
}
componentPortFilter = new RawPrintFilter("ExComp");
SocketAcceptor componentAcceptor = connManager.getComponentAcceptor();
if (componentAcceptor != null) {
componentAcceptor.getFilterChain().addBefore("xmpp", "rawDebugger", componentPortFilter);
}
multiplexerPortFilter = new RawPrintFilter("CM");
SocketAcceptor multiplexerAcceptor = connManager.getMultiplexerSocketAcceptor();
if (multiplexerAcceptor != null) {
multiplexerAcceptor.getFilterChain().addBefore("xmpp", "rawDebugger", multiplexerPortFilter);
}
interpretedPrinter = new InterpretedXMLPrinter();
if (JiveGlobals.getBooleanProperty("plugin.debugger.interpretedAllowed")) {
// Add the packet interceptor that prints interpreted XML
InterceptorManager.getInstance().addInterceptor(interpretedPrinter);
}
// Listen to property events
PropertyEventDispatcher.addListener(this);
}
示例12: accept
import org.apache.mina.transport.socket.nio.SocketAcceptor; //导入依赖的package包/类
public void accept(final NetworkTransportConfiguration config, final ProtocolEngineFactory factory,
final SSLContextFactory sslFactory)
{
int processors = config.getConnectorProcessors();
if (Transport.TCP.equalsIgnoreCase(config.getTransport()))
{
_acceptor = new SocketAcceptor(processors, new NewThreadExecutor());
SocketAcceptorConfig sconfig = (SocketAcceptorConfig) _acceptor.getDefaultConfig();
sconfig.setThreadModel(ExecutorThreadModel.getInstance("MinaNetworkTransport(Acceptor)"));
SocketSessionConfig sc = (SocketSessionConfig) sconfig.getSessionConfig();
sc.setTcpNoDelay(config.getTcpNoDelay());
sc.setSendBufferSize(config.getSendBufferSize());
sc.setReceiveBufferSize(config.getReceiveBufferSize());
if (config.getHost().equals(WILDCARD_ADDRESS))
{
_address = new InetSocketAddress(config.getPort());
}
else
{
_address = new InetSocketAddress(config.getHost(), config.getPort());
}
}
else
{
throw new TransportException("Unknown transport: " + config.getTransport());
}
try
{
_acceptor.bind(_address, new MinaNetworkHandler(sslFactory, factory));
}
catch (IOException e)
{
throw new TransportException("Could not bind to " + _address, e);
}
}
示例13: doOpen
import org.apache.mina.transport.socket.nio.SocketAcceptor; //导入依赖的package包/类
@Override
protected void doOpen() throws Throwable {
// set thread pool.
acceptor = new SocketAcceptor(getUrl().getPositiveParameter(Constants.IO_THREADS_KEY, Constants.DEFAULT_IO_THREADS),
Executors.newCachedThreadPool(new NamedThreadFactory("MinaServerWorker",
true)));
// config
SocketAcceptorConfig cfg = (SocketAcceptorConfig) acceptor.getDefaultConfig();
cfg.setThreadModel(ThreadModel.MANUAL);
// set codec.
acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new MinaCodecAdapter(getCodec(), getUrl(), this)));
acceptor.bind(getBindAddress(), new MinaHandler(getUrl(), this));
}
示例14: run_startup_configurations
import org.apache.mina.transport.socket.nio.SocketAcceptor; //导入依赖的package包/类
public static final void run_startup_configurations() {
System.out.print("Loading Login Server...");
userLimit = ServerConfig.userLimit;
serverName = ServerConfig.serverName;
eventMessage = ServerConfig.eventMessage;
flag = ServerConfig.flag;
adminOnly = ServerConfig.adminOnly;
maxCharacters = ServerConfig.maxCharacters;
ByteBuffer.setUseDirectBuffers(false);
ByteBuffer.setAllocator(new SimpleByteBufferAllocator());
acceptor = new SocketAcceptor();
final SocketAcceptorConfig cfg = new SocketAcceptorConfig();
cfg.getSessionConfig().setTcpNoDelay(true);
cfg.setDisconnectOnUnbind(true);
cfg.getFilterChain().addLast("codec", new ProtocolCodecFilter(new MapleCodecFactory()));
try {
InetSocketadd = new InetSocketAddress(PORT);
acceptor.bind(InetSocketadd, new MapleServerHandler(), cfg);
System.out.println(" Complete!");
System.out.println("Login Server is listening on port " + PORT + ".");
} catch (IOException e) {
System.out.println(" Failed!");
System.err.println("Could not bind to port " + PORT + ": " + e);
}
}
示例15: Router
import org.apache.mina.transport.socket.nio.SocketAcceptor; //导入依赖的package包/类
/**
* Create a new instance.
*
* @param options The router configuration options. Note that, due
* to a MINA limitation, the IO.Use-Direct-Buffers
* option applies globally, so using multiple router
* instances with this option set to different values
* will clash.
*
* @throws IOException if an network error during router
* initialisation.
* @throws IllegalConfigOptionException If an option in the configuratiion
* options is invalid.
*/
@SuppressWarnings ("unchecked")
public Router (RouterOptions options)
throws IOException, IllegalConfigOptionException
{
this.notifyListeners =
new ListenerList<NotifyListener>
(NotifyListener.class, "notifyReceived", Notify.class, Keys.class);
this.closeListeners =
new ListenerList<CloseListener>
(CloseListener.class, "routerClosing", Router.class);
this.routerOptions = options;
this.sessions = new ConcurrentHashSet<IoSession> ();
this.executor = newCachedThreadPool ();
this.acceptor =
new SocketAcceptor (getRuntime ().availableProcessors () + 1,
executor);
setUseDirectBuffers (options.getBoolean ("IO.Use-Direct-Buffers"));
/*
* Setup IO filter chain with codec and then thread pool. NOTE:
* The read throttling system needs an ExecutorFilter to glom
* onto: it's not clear that we gain any other benefit from it
* since notification processing is non-blocking. See
* http://mina.apache.org/configuring-thread-model.html.
*/
DefaultIoFilterChainBuilder filters = new DefaultIoFilterChainBuilder ();
filters.addLast ("codec", ClientFrameCodec.FILTER);
filters.addLast ("threadPool", new ExecutorFilter (executor));
bind (options.listenURIs (), this, filters,
(Filter<InetAddress>)routerOptions.get ("Require-Authenticated"));
}