本文整理汇总了Java中org.apache.mina.filter.codec.serialization.ObjectSerializationCodecFactory类的典型用法代码示例。如果您正苦于以下问题:Java ObjectSerializationCodecFactory类的具体用法?Java ObjectSerializationCodecFactory怎么用?Java ObjectSerializationCodecFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ObjectSerializationCodecFactory类属于org.apache.mina.filter.codec.serialization包,在下文中一共展示了ObjectSerializationCodecFactory类的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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) {
}
}
}
开发者ID:kefik,项目名称:Pogamut3,代码行数:27,代码来源:TCMinaClient.java
示例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);
}
开发者ID:java-scott,项目名称:java-project,代码行数:24,代码来源:Server.java
示例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, "�˿��Ѿ�ռ�ã��뻻���˿ڣ�");
}
}
开发者ID:ganhang,项目名称:My-ChatSystem,代码行数:25,代码来源:Server.java
示例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);
}
开发者ID:fix-protocol-tools,项目名称:STAFF,代码行数:23,代码来源:TcpServer.java
示例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();
}
开发者ID:ameizi,项目名称:mina-examples,代码行数:23,代码来源:HelloTcpClient.java
示例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();
}
开发者ID:ganhang,项目名称:My-ChatSystem,代码行数:36,代码来源:Client.java
示例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.");
}
开发者ID:fix-protocol-tools,项目名称:STAFF,代码行数:44,代码来源:TcpClient.java
示例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));
}
开发者ID:induwarabas,项目名称:simple-event-loop,代码行数:11,代码来源:Server.java
示例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));
}
开发者ID:induwarabas,项目名称:simple-event-loop,代码行数:15,代码来源:Client.java
示例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));
}
开发者ID:ameizi,项目名称:mina-examples,代码行数:13,代码来源:HelloUdpServer.java
示例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));
}
开发者ID:ameizi,项目名称:mina-examples,代码行数:11,代码来源:HelloTcpServer.java
示例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();
// }
}
开发者ID:sics-sse,项目名称:moped,代码行数:37,代码来源:PluginWebServicePublisher.java
示例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);
}
开发者ID:knowpd,项目名称:p2p-file-sharing-system,代码行数:61,代码来源:PeerlessSendUdpMessageSupport.java
示例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);
}
开发者ID:knowpd,项目名称:p2p-file-sharing-system,代码行数:20,代码来源:PeerlessUdpServer.java
示例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;
}
}
开发者ID:knowpd,项目名称:p2p-file-sharing-system,代码行数:42,代码来源:PeerlessClientSupport.java
示例16: register
import org.apache.mina.filter.codec.serialization.ObjectSerializationCodecFactory; //导入依赖的package包/类
public boolean register(NioSocketConnector connector, SocketAddress address,
String name, String id, String password, String question,
String passwordReminder, boolean useSsl) {
System.out.println("This is address: " + address);
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();
register m = new register();
m.setSequence(0);
m.setCommand("REGISTER");
m.setUserId(id);
m.setpassword(password);
m.setQuestion(question);
m.setpasswordReminder(passwordReminder);
session.write(m);
/*session.write("REGISTER " + id + CommonConfig.delimeter + name
+ CommonConfig.delimeter + password
+ CommonConfig.delimeter + question
+ CommonConfig.delimeter + passwordReminder);*/
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
开发者ID:knowpd,项目名称:p2p-file-sharing-system,代码行数:56,代码来源:PeerlessClientSupport.java
示例17: main
import org.apache.mina.filter.codec.serialization.ObjectSerializationCodecFactory; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
NioSocketAcceptor acceptor = new NioSocketAcceptor();
DefaultIoFilterChainBuilder chain = acceptor.getFilterChain();
MdcInjectionFilter mdcInjectionFilter = new MdcInjectionFilter();
chain.addLast("mdc", mdcInjectionFilter);
SigHashTable sht = new SigHashTable();
/*
* FileSignature d0=new FileSignature("test data");
* SigManager.printByteArray(d0);
*
* FileSignature d1=new FileSignature(new File("ftphome//test.txt"));
* SigManager.printByteArray(d1);
*
* FileSignature d2=newFileSignature(
* "Design and Implementation of Virtualized Network Simulator");
* SigManager.printByteArray(d2);
*
* sht.addSignature(d0); sht.addSignature(d1); sht.addSignature(d2);
*/
PeerlessDbSupport peerlessDbSupport = new PeerlessDbSupport(ServerConfig.ServerDb);
peerlessDbSupport.connect();
peerlessDbSupport.createSchema();
SuperPeerManager superPeerManager = new SuperPeerManager();
// Add SSL filter if SSL is enabled.
if (USE_SSL) {
addSSLSupport(chain);
}
// chain.addLast("codec", new ProtocolCodecFilter(new
// TextLineCodecFactory()));
chain.addLast("codec", new ProtocolCodecFilter(
new ObjectSerializationCodecFactory()));
addLogger(chain);
// Bind
acceptor.setHandler(new PeerlessProtocolHandler(sht, peerlessDbSupport, superPeerManager));
acceptor.bind(new InetSocketAddress(ServerConfig.PORT));
System.out.println("Listening on port " + ServerConfig.PORT);
try {
new PeerlessUdpServer(peerlessDbSupport, sht);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
开发者ID:knowpd,项目名称:p2p-file-sharing-system,代码行数:57,代码来源:PeerlessServerMain.java
示例18: main
import org.apache.mina.filter.codec.serialization.ObjectSerializationCodecFactory; //导入依赖的package包/类
public static void main(String[] args) throws Throwable {
init(args);
NioSocketConnector connector = new NioSocketConnector();
// Configure the service.
connector.setConnectTimeoutMillis(CONNECT_TIMEOUT);
if (USE_CUSTOM_CODEC) {
connector.getFilterChain().addLast("codec",
new ProtocolCodecFilter(new SumUpProtocolCodecFactory(false)));
} else {
connector.getFilterChain().addLast("codec",
new ProtocolCodecFilter(new ObjectSerializationCodecFactory()));
}
int[] values = new int[]{};
connector.getFilterChain().addLast("logger", new LoggingFilter());
connector.setHandler(new ClientSessionHandler(values));
long time = System.currentTimeMillis();
IoSession session;
for (; ; ) {
try {
System.out.println(host + " " + port + " " + fileTest);
ConnectFuture future = connector.connect(new InetSocketAddress(host, port));
future.awaitUninterruptibly();
session = future.getSession();
File file = new File(fileTest);
FileInputStream is = new FileInputStream(file);
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
int data = br.read();
int count = 0;
IoBuffer ib = IoBuffer.allocate(274);
ib.setAutoExpand(true);
boolean flagcount = false;
while(data != -1){
data = br.read();
ib.put((byte)data);
if (flagcount){count++;}
if (data==13){
count=1;
flagcount = true;
LOGGER.debug(ib.toString());
}
if (count == 4) {
ib.flip();
session.write(ib);
ib = IoBuffer.allocate(274);
ib.setAutoExpand(true);
flagcount = false;
count = 0;
//Thread.sleep(500);
}
}
break;
} catch (RuntimeIoException e) {
LOGGER.error("Failed to connect.");
e.printStackTrace();
Thread.sleep(5000);
}
}
time = System.currentTimeMillis() - time;
LOGGER.info("Time " + time);
// wait until the summation is done
session.getCloseFuture().awaitUninterruptibly();
connector.dispose();
}
开发者ID:jenbabis22,项目名称:MXCashMarketDataDrv,代码行数:74,代码来源:DriverClient.java
注:本文中的org.apache.mina.filter.codec.serialization.ObjectSerializationCodecFactory类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论