本文整理汇总了Java中org.apache.mina.filter.codec.serialization.ObjectSerializationCodecFactory类的典型用法代码示例。如果您正苦于以下问题:Java ObjectSerializationCodecFactory类的具体用法?Java ObjectSerializationCodecFactory怎么用?Java ObjectSerializationCodecFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ObjectSerializationCodecFactory类属于org.apache.mina.filter.codec.serialization包,在下文中一共展示了ObjectSerializationCodecFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: connect
import org.apache.mina.filter.codec.serialization.ObjectSerializationCodecFactory; //导入依赖的package包/类
public void connect() {
synchronized(mutex) {
if (connected.getFlag()) return;
if (connecting.getFlag()) return;
log.warning("Connecting to TC at " + getHost() + ":" + getPort() + " ...");
connecting.setFlag(true);
}
try {
ioConnector = new NioSocketConnector();
ioConnector.setHandler(this);
ioConnector.getFilterChain().addLast("codec", new ProtocolCodecFilter(new ObjectSerializationCodecFactory()));
connectFuture = ioConnector.connect(address);
connectFuture.addListener(connectionListener);
} catch (Exception e1) {
try {
connecting.setFlag(false);
} catch (Exception e2) {
}
}
}
示例2: main
import org.apache.mina.filter.codec.serialization.ObjectSerializationCodecFactory; //导入依赖的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);
}
示例3: startServer
import org.apache.mina.filter.codec.serialization.ObjectSerializationCodecFactory; //导入依赖的package包/类
/**
* �������
* @param args
* @throws IOException
*/
public void startServer() {
server = new NioSocketAcceptor();
//�������ݹ�����
DefaultIoFilterChainBuilder filterChain = server.getFilterChain();
filterChain.addLast("myChin", new ProtocolCodecFilter(
new ObjectSerializationCodecFactory()));
//filterChain.addLast("textCode",new ProtocolCodecFilter(
// new TextLineCodecFactory(Charset.forName("UTF-8"))));
serverIOHandler = new ServerIOHandler(severFrame);
server.setHandler(serverIOHandler);
//�����������˿� --- ����������
try {
server.bind(new InetSocketAddress(port));
} catch (IOException e) {
Tools.show(severFrame, "�˿��Ѿ�ռ�ã��뻻���˿ڣ�");
}
}
示例4: open
import org.apache.mina.filter.codec.serialization.ObjectSerializationCodecFactory; //导入依赖的package包/类
public void open() throws Exception {
if (logger.isDebugEnabled()) {
logger.debug("Start logger.");
}
SocketAcceptorConfig cfg = new SocketAcceptorConfig();
cfg.setReuseAddress(true);
if(useFixCodec) {
cfg.getFilterChain().addLast("codec",
new ProtocolCodecFilter(new ServerProtocolCodecFactory()));
} else {
cfg.getFilterChain().addLast("codec",
new ProtocolCodecFilter(new ObjectSerializationCodecFactory()));
}
cfg.getFilterChain().addLast("logger", new LoggingFilter());
acceptor.bind(new InetSocketAddress(port), this, cfg);
System.out.println("Listening on port " + port);
}
示例5: main
import org.apache.mina.filter.codec.serialization.ObjectSerializationCodecFactory; //导入依赖的package包/类
public static void main(String[] args) {
NioSocketConnector connector = new NioSocketConnector(); //TCP Connector
connector.getFilterChain().addLast("logging", new LoggingFilter());
connector.getFilterChain().addLast("codec",new ProtocolCodecFilter(new ObjectSerializationCodecFactory()));
connector.getFilterChain().addLast("mdc", new MdcInjectionFilter());
connector.setHandler(new HelloClientHandler());
IoSession session;
for (;;) {
try {
ConnectFuture future = connector.connect(new InetSocketAddress(HOSTNAME, PORT));
future.awaitUninterruptibly();
session = future.getSession();
break;
} catch (RuntimeIoException e) {
System.err.println("Failed to connect.");
e.printStackTrace();
}
}
session.getCloseFuture().awaitUninterruptibly();
connector.dispose();
}
示例6: connect
import org.apache.mina.filter.codec.serialization.ObjectSerializationCodecFactory; //导入依赖的package包/类
/**
* �����ͻ�������
*/
public boolean connect() {
// ʵ���� �������� Socket����
client = new NioSocketConnector();
// �������ݹ�����
DefaultIoFilterChainBuilder filterChain = client.getFilterChain();
//filterChain.addLast("textCode", new ProtocolCodecFilter(
// new TextLineCodecFactory(Charset.forName("UTF-8"))));
filterChain.addLast("myChin", new ProtocolCodecFilter(
new ObjectSerializationCodecFactory()));
// �ͻ��˴������
ClientIoHandler clientIoHandler = new ClientIoHandler(loginFrame,client);
client.setHandler(clientIoHandler);
clientIoHandler.setRegisterFrame(registerFrame);
// ���ӷ�����
ConnectFuture future = client.connect(new InetSocketAddress(
IP, Port));
// �ȴ�
future.awaitUninterruptibly();
// �õ��Ự����
try {
session = future.getSession();
return true;
} catch (Exception e) {
Tools.show(loginFrame, "�����ӷ�������������û������");
client.dispose();
if(registerFrame!=null)
registerFrame.dispose();
return false;
}
// session.getCloseFuture().awaitUninterruptibly();
}
示例7: open
import org.apache.mina.filter.codec.serialization.ObjectSerializationCodecFactory; //导入依赖的package包/类
/**
* Open client socket.
* <p/>
* throws Exception on errors
*/
public void open() throws Exception {
if(logger.isDebugEnabled()) {
logger.debug("Start logger.");
}
connector.setWorkerTimeout(10000);
// Configure the service.
SocketConnectorConfig cfg = new SocketConnectorConfig();
cfg.setConnectTimeout(CONNECT_TIMEOUT);
cfg.setConnectTimeout(10);
if(useFixCodec) {
cfg.getFilterChain().addLast("codec",
new ProtocolCodecFilter(new ServerProtocolCodecFactory()));
} else {
cfg.getFilterChain().addLast("codec", new ProtocolCodecFilter(
new ObjectSerializationCodecFactory()));
}
cfg.getFilterChain().addLast("logger", new LoggingFilter());
for (int i=0; i < 20; i++) {
try {
System.out.println("Try connect.");
final ConnectFuture future =
connector.connect(new InetSocketAddress(host, port), this, cfg);
future.join();
session = future.getSession();
return;
} catch (RuntimeIOException e) {
Thread.sleep(5000);
}
}
throw new BuildException("Failed connect.");
}
示例8: start
import org.apache.mina.filter.codec.serialization.ObjectSerializationCodecFactory; //导入依赖的package包/类
public void start(int port) throws IOException {
acceptor = new NioSocketAcceptor();
acceptor.getFilterChain().addLast( "codec", new ProtocolCodecFilter(new ObjectSerializationCodecFactory()));
acceptor.setHandler(this);
acceptor.getSessionConfig().setReadBufferSize( 2048 );
acceptor.getSessionConfig().setIdleTime( IdleStatus.WRITER_IDLE, 10);
acceptor.getSessionConfig().setIdleTime( IdleStatus.READER_IDLE, 10);
acceptor.setReuseAddress(true);
acceptor.bind(new InetSocketAddress(port));
}
示例9: connect
import org.apache.mina.filter.codec.serialization.ObjectSerializationCodecFactory; //导入依赖的package包/类
public void connect(String host, int port) throws IOException, ExecutionException, InterruptedException {
this.host = host;
this.port = port;
connector = new NioSocketConnector();
connector.setConnectTimeoutMillis(4000);
connector.getFilterChain().addLast("codec",
new ProtocolCodecFilter(new ObjectSerializationCodecFactory()));
connector.getSessionConfig().setIdleTime(IdleStatus.WRITER_IDLE, 10);
connector.getSessionConfig().setIdleTime(IdleStatus.READER_IDLE, 10);
connector.getSessionConfig().setReceiveBufferSize(2048);
connector.setHandler(this);
System.out.println("Connecting.. " + host + ":" + port + DateTime.now().toString());
future = connector.connect(new InetSocketAddress(host, port));
}
示例10: main
import org.apache.mina.filter.codec.serialization.ObjectSerializationCodecFactory; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
NioDatagramAcceptor acceptor = new NioDatagramAcceptor();//UDP Acceptor
acceptor.getFilterChain().addLast("logging", new LoggingFilter());
acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new ObjectSerializationCodecFactory()));
acceptor.getFilterChain().addLast("mdc", new MdcInjectionFilter());
acceptor.setHandler(new HelloServerHandler());
acceptor.getSessionConfig().setReadBufferSize(2048);
acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 10);
DatagramSessionConfig dcfg = acceptor.getSessionConfig();
dcfg.setReuseAddress(true);
acceptor.bind(new InetSocketAddress(PORT));
}
示例11: main
import org.apache.mina.filter.codec.serialization.ObjectSerializationCodecFactory; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
IoAcceptor acceptor = new NioSocketAcceptor(); //TCP Acceptor
acceptor.getFilterChain().addLast("logging", new LoggingFilter());
acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new ObjectSerializationCodecFactory()));
acceptor.getFilterChain().addLast("mdc", new MdcInjectionFilter());
acceptor.setHandler(new HelloServerHandler());
acceptor.getSessionConfig().setReadBufferSize(2048);
acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 10);
acceptor.bind(new InetSocketAddress(PORT));
}
示例12: main
import org.apache.mina.filter.codec.serialization.ObjectSerializationCodecFactory; //导入依赖的package包/类
public static void main(String[] args) {
/* Start listening for incoming connections
* (see e.g. https://mina.apache.org/mina-project/quick-start-guide.html) */
SocketAcceptor socketAcceptor = new NioSocketAcceptor();
socketAcceptor.getFilterChain().addLast("logger", new LoggingFilter());
socketAcceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new ObjectSerializationCodecFactory())); //TODO: This is a default codec, should ideally not be used
// socketAcceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new TextLineCodecFactory(Charset.forName("UTF-8"))));
ServerHandler handler = new ServerHandler();
socketAcceptor.setHandler(handler);
try {
socketAcceptor.setReuseAddress(true);
socketAcceptor.bind(new InetSocketAddress(SOCKET_PORT));
} catch (IOException e) {
e.printStackTrace();
}
/* Make the php-java interface accessible */
PluginWebServicesImpl pws = new PluginWebServicesImpl(handler);
Endpoint.publish(PUB_ADDRESS, pws);
System.out.println("published");
// try {
// Configuration config = new Configuration();
// config.configure();
//
// sqlSessionFactory = config.buildSessionFactory(new StandardServiceRegistryBuilder().
// applySettings(config.getProperties()).build());
// } catch (Exception ex) {
// ex.printStackTrace();
// }
}
示例13: connectAndSend
import org.apache.mina.filter.codec.serialization.ObjectSerializationCodecFactory; //导入依赖的package包/类
/**
* Default constructor.
*/
public void connectAndSend() {
LOGGER.debug(ipAddress +":"+ portNo);
SocketAddress address = parseSocketAddress(ipAddress +":"+ portNo);
LOGGER.debug("UDPClient::UDPClient");
LOGGER.debug("Created a datagram connector");
connector = new NioDatagramConnector();
LOGGER.debug("Setting the handler");
connector.setHandler(this);
IoFilter LOGGING_FILTER = new LoggingFilter();
IoFilter CODEC_FILTER = new ProtocolCodecFilter(
new TextLineCodecFactory());
connector.getFilterChain().addLast("mdc", new MdcInjectionFilter());
connector.getFilterChain().addLast("codec", new ProtocolCodecFilter(new ObjectSerializationCodecFactory()));
connector.getFilterChain().addLast("logger", LOGGING_FILTER);
LOGGER.debug("About to connect to the server...");
ConnectFuture future1 = connector.connect(address);
future1.awaitUninterruptibly();
if (!future1.isConnected()) {
return;
}
session = future1.getSession();
// try {
//sendData(fileSignature);
/*
UdpMessage m = new UdpMessage();
m.setSequence(0);
m.setFileSignature(fileSignature);
session.write(m);*/
RequestSignatureMessage signatureMessage = new RequestSignatureMessage();
FileSignature fileSignature;
try {
fileSignature = new FileSignature(query);
signatureMessage.setSequence(0);
signatureMessage.setFileSignature(fileSignature);
signatureMessage.setMatches(matches);
System.out.println("Sending the query: " + query);
System.out.println("[PeerlessSendUdpMessageSupport] file signature" + fileSignature);
session.write(signatureMessage);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//fileSignature.setFileSignature(query);
}
示例14: PeerlessUdpServer
import org.apache.mina.filter.codec.serialization.ObjectSerializationCodecFactory; //导入依赖的package包/类
public PeerlessUdpServer(PeerlessDbSupport peerlessDbSupport, SigHashTable sht) throws IOException {
this.sht=sht;
this.peerlessDbSupport=peerlessDbSupport;
NioDatagramAcceptor acceptor = new NioDatagramAcceptor();
acceptor.setHandler(new PeerlessUdpServerHandler(this));
DefaultIoFilterChainBuilder chain = acceptor.getFilterChain();
chain.addLast("logger", new LoggingFilter());
DatagramSessionConfig dcfg = acceptor.getSessionConfig();
dcfg.setReuseAddress(true);
chain.addLast("codec", new ProtocolCodecFilter(new ObjectSerializationCodecFactory()));
acceptor.bind(new InetSocketAddress(PORT));
System.out.println("UDPServer listening on port " + PORT);
}
示例15: connect
import org.apache.mina.filter.codec.serialization.ObjectSerializationCodecFactory; //导入依赖的package包/类
public boolean connect(NioSocketConnector connector, SocketAddress address,
boolean useSsl) {
if (session != null && session.isConnected()) {
throw new IllegalStateException(
"Already connected. Disconnect first.");
}
try {
IoFilter LOGGING_FILTER = new LoggingFilter();
IoFilter CODEC_FILTER = new ProtocolCodecFilter(
new TextLineCodecFactory());
connector.getFilterChain().addLast("mdc", new MdcInjectionFilter());
//connector.getFilterChain().addLast("codec", CODEC_FILTER);
connector.getFilterChain().addLast("codec", new ProtocolCodecFilter(new ObjectSerializationCodecFactory()));
connector.getFilterChain().addLast("logger", LOGGING_FILTER);
if (useSsl) {
SSLContext sslContext = BogusSslContextFactory
.getInstance(false);
SslFilter sslFilter = new SslFilter(sslContext);
sslFilter.setUseClientMode(true);
connector.getFilterChain().addFirst("sslFilter", sslFilter);
}
connector.setHandler(handler);
ConnectFuture future1 = connector.connect(address);
future1.awaitUninterruptibly();
if (!future1.isConnected()) {
return false;
}
session = future1.getSession();
login();
return true;
} catch (Exception e) {
return false;
}
}