介绍
Server Transport 即传输层,是建立在通信信道建立成功和传输指令交互成功的基础上的一层用于传送数据的层,类似TCP、UDP,它的主要的作用就是输送我们定义的数据,数据格式的数据结构则可以自己进行约定,如字符流、字节流等,也可以为XML或其他数据结构实现的数据格式。
在Transport建立过程中,Server与Client端需要持有一些数据成员,如对方的信任信息、连接地址等socket参数、操作柄的代理工厂。
这样建立Transport后则可以实现数据传输、指令下达、报告提交等功能。
部分代码
package thread;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* This ServerTransport is work in multi thread env
*
* @author daniel
*
*/
public class ServerTransport {
private static final Log _log = LogFactory.getLog(ServerTransport.class);
private final Object _lock = new Object();
private boolean _readyFlag = false;
private boolean _stopFlag;
private final AsynchronousCaller _asyncCaller;
/**
* Initialization AsynchronousCaller
* @param asyncThreadPoolSize
*/
public ServerTransport(int asyncThreadPoolSize) {
if(asyncThreadPoolSize<0){
throw new IllegalArgumentException("illegal Server Transport poolSize: "+asyncThreadPoolSize);
}
_asyncCaller = new AsynchronousCaller(asyncThreadPoolSize);
//Do some other things about each transport!
}
/*
* Operate Handler
*/
//check ready
public boolean isReady(){
synchronized(_lock){
return _readyFlag;
}
}
//start
public void start() throws Exception {
if (isStopped()) {
return;
}
_asyncCaller.start();
setReady(true);
}
//stop
public void stop() {
_asyncCaller.stop();
setReady(false);
setStop(false);
}
//set ready
private void setReady(boolean b) {
synchronized(_lock){
_readyFlag = b;
}
}
//set ready
private void setStop(boolean b) {
synchronized(_lock){
_stopFlag = b;
}
}
//check stop
private boolean isStopped() {
synchronized(_lock){
return _stopFlag;
}
}
}
/*
* Construct an Asynchronous Operate way
*/
class AsynchronousCaller {
private final ThreadPoolExecutor _executor;
/*
* Generate an Thread pool with some thread factory & thread group
*/
public AsynchronousCaller(int poolSize) {
if (poolSize <= 0) {
throw new IllegalArgumentException("illegal pool size: "+poolSize);
}
ThreadGroup threadGroup = new ThreadGroup("Async Caller Group");
ThreadGroupFactory tFactory= new ThreadGroupFactory(threadGroup, "AsyncCaller-");
tFactory.createDaemonThreads(true);
_executor = new ThreadPoolExecutor(poolSize,
poolSize,
Long.MAX_VALUE,
TimeUnit.NANOSECONDS,
new LinkedBlockingQueue(),
tFactory,
new ThreadPoolExecutor.AbortPolicy());
}
public void start() {
_executor.prestartAllCoreThreads();
}
public void stop() {
_executor.shutdown();
}
}
- 大小: 1.1 MB
分享到:
相关推荐
G.852.2 (Enterprise Viewpoint Description of Transport Network Resource Model, March 1999) defines corresponding enterprise-wide network resource concepts that are management abstractions of G.805 ...
Many books such as [Rescorla01], [Comer00], and [Hall00] describe the Internet’s client-server model and communication protocol design principles. None guide Federal users and system administrators ...
The Data Model 5 Different Physical Tables 6 Integration and Transformation ProcessingGranular Data 8 Historical Data 9 Timestamping 10 Data Relationships 10 Generic Data versus Specific Data 11 Data ...
The Transport Layer: TCP, UDP, and SCTP Section 2.1. Introduction Section 2.2. The Big Picture Section 2.3. User Datagram Protocol (UDP) Section 2.4. Transmission Control Protocol (TCP) ...
File Server Protocol Review: CIFS, NFS, and DAFS Backup Protocols: NDMP and EXTENDED COPY Optical Technologies: SONET/SDH, DWDM/CWDM, and RPR/802.17 Virtualization Implementations: Host, ...
HttpCore is a set of low level HTTP transport components that can be used to build custom client and server side ...blocking, event driven I/O model based on Java NIO.
HttpCore is a set of low level HTTP transport components that can be used to build custom client and server side ...
Chapter 2 The OSI Model and the TCP/IP Protocol Suite 18 Chapter 3 Underlying Technologies 46 Part 2 Network Layer 93 Chapter 4 Introduction to Network Layer 94 Chapter 5 IPv4 Addresses 114 Chapter 6 ...
Switch(config)# aaa new-model 2.配置主机名 Switch(config)# hostname sw1 3.配置本地用户名口令,以便在带外服务器不可用时能够访问交换机 sw1(config)# username cisco password cisco 4.配置SSH sw1...
further than the JavaMail API, which offers a protocol-independent model for working with IMAP, POP, SMTP, MIME, and all those other Internet-related messaging protocols. With the help of the ...
and service components, which process and transport data (such as query processors and cursor engines). In addition, OLE DB includes a bridge to ODBC to enable continued support for the broad range ...
1.3.2 SAP NetWeaver Application Server for Java: System Architecture 1.3.3 SAP NetWeaver AS Java System Logical Layers 1.4 Installation Options 1.4.1 Case 1: SAP Process Integration Dual Stack ...
He has worked with numerous Microsoft products and technologies and is an expert in BizTalk, SQL Server, SharePoint, Compute Cluster Server, and of course Visual Studio and the .NET Framework....
Using the SQL Server Data Provider 435 TDS 436 Exercise 9.2 Using TypedDataSet 437 Remoting 439 Data Controls 440 DataGrid 440 Exercise 9.3 Using TypedDataSet and DataRelation 441 DataList 446...
启动登录进程 login [local|tacacs server] 设置登录密码 password password 五、配置IP寻址 1. IP地址分类 IP地址分为网络地址和主机地址二个部分,A类地址前8位为网络地址,后24位为主机地址,B类地址16...
PEP 3333: Python Web Server Gateway Interface v1.0.1 Other Language Changes New, Improved, and Deprecated Modules email elementtree functools itertools collections threading datetime and time ...
Layer 4—Transport 10 Layer 3—Network 11 Layer 2—Data Link 11 Layer 1—Physical 12 OSI Reference Model Layers and Information Exchange 13 Headers, Trailers, and Data 13 TCP/IP Protocol Suite 14 TCP/...
The Transport Layer 78 T3 A T1 Layer 5:The Session Layer 78 F T3 E B Layer 6:The Presentation Layer 79 D T3 Layer 7:The Application Layer 80 T1 C T3 OSI...
The TCP/IP Network Model.............................................................................16 Non-IP Protocols...................................................................................