介绍
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
分享到:
相关推荐
The Transport Layer is a critical component in the OSI (Open Systems Interconnection) model, responsible for ensuring reliable data transmission between hosts. It operates independently of lower-level...
- **服务器模型(Server Models)**:提供服务,如控制灯泡亮度的照明模型,或者调节温度的环境传感器模型。 - **客户端模型(Client Models)**:发起请求,如调用远程设备的服务器模型功能。 模型之间通过消息进行...
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 ...
为了实现这个过程,你需要在Android项目中引入Gson库,并确保你的实体类(如`ImageModel`)在两端都有对应的定义,包括相同的名字和属性。 三、Android与WebService的通信步骤 1. 创建SoapObject,设置方法名和参数...
RTSP(Real Time Streaming Protocol,实时流传输协议)是一种应用层协议,用于控制...如果你打算进一步研究,还可以探索RTSP的扩展特性,如SSM(Session Subscription Model)和多播支持,以适应更广泛的应用需求。
在本压缩包“Laravel开发-laravel-kendo-server-filters .zip”中,重点内容是关于使用Laravel框架与Kendo UI的服务器过滤功能。Laravel是一款流行的PHP框架,用于构建优雅、高效的Web应用程序,而Kendo UI则是一个...
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 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) ...
项目与本地MS SQL数据库进行交互,这意味着数据存储和检索都依赖于微软的SQL Server数据库管理系统。这种数据库选择提供了可靠的数据存储和高效的查询性能,适合管理大量运输公司相关的数据,如车辆信息、路线、订单...
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.
12. **软件架构模式**:如MVC(Model-View-Controller)或MVVM(Model-View-ViewModel)可以帮助组织复杂的项目结构,提高代码的可读性和可维护性。 综上所述,"Transport-company"项目可能涵盖了C#语言的许多核心...
ROS提供了许多相机相关的包,如`image_transport`和`camera_info_manager`,用于处理相机数据。 7. **Fiducial Detector Model**: Fiducial探测器模型用于识别机器人环境中的标记物,例如AR标签,帮助机器人定位...
HttpCore is a set of low level HTTP transport components that can be used to build custom client and server side ...
no aaa new-model ! dot11 ssid cisco authentication open guest-mode ! ! ! bridge irb ! ! interface Dot11Radio0 no ip address no ip route-cache ! ssid XXXX ! short-slot-time speed basic-1.0 basic-2.0 ...
AspEmail是由Mercury Mail Transport System提供的一个ASP邮件组件,它允许开发者通过SMTP服务器发送邮件。AspEmail支持HTML格式的邮件,可以设置发件人、收件人、抄送人、密送人等参数,并能添加附件。使用AspEmail...