|
@@ -33,6 +33,10 @@ public class DDSPublisher {
|
|
|
private final ExecutorService matchService = Executors.newSingleThreadExecutor();
|
|
|
private static final int MAX_RETRIES = 5; // 最大重试次数
|
|
|
private int retryCount = 0; // 当前重试计数
|
|
|
+ private DataWriter dw;
|
|
|
+ private Publisher pub;
|
|
|
+ private DomainParticipant dp;
|
|
|
+ private DomainParticipantFactory dpf;
|
|
|
|
|
|
@PostConstruct
|
|
|
private void initialize(){
|
|
@@ -62,12 +66,12 @@ public class DDSPublisher {
|
|
|
private void doInitialize() {
|
|
|
log.info("Start Publisher");
|
|
|
|
|
|
- DomainParticipantFactory dpf = TheParticipantFactory.WithArgs(new StringSeqHolder(params.toArgs()));
|
|
|
+ dpf = TheParticipantFactory.WithArgs(new StringSeqHolder(params.toArgs()));
|
|
|
if (dpf == null) {
|
|
|
throw new InitialFailedException("ERROR: Domain Participant Factory not found");
|
|
|
}
|
|
|
|
|
|
- DomainParticipant dp = dpf.create_participant(4,
|
|
|
+ dp = dpf.create_participant(4,
|
|
|
PARTICIPANT_QOS_DEFAULT.get(), null, DEFAULT_STATUS_MASK.value);
|
|
|
if (dp == null) {
|
|
|
throw new InitialFailedException("ERROR: Domain Participant creation failed");
|
|
@@ -87,7 +91,7 @@ public class DDSPublisher {
|
|
|
throw new InitialFailedException("ERROR: Topic creation failed");
|
|
|
}
|
|
|
|
|
|
- Publisher pub = dp.create_publisher(PUBLISHER_QOS_DEFAULT.get(), null,
|
|
|
+ pub = dp.create_publisher(PUBLISHER_QOS_DEFAULT.get(), null,
|
|
|
DEFAULT_STATUS_MASK.value);
|
|
|
if (pub == null) {
|
|
|
throw new InitialFailedException("ERROR: Publisher creation failed");
|
|
@@ -135,7 +139,7 @@ public class DDSPublisher {
|
|
|
qosh.value.reliability.kind =
|
|
|
ReliabilityQosPolicyKind.RELIABLE_RELIABILITY_QOS;
|
|
|
}
|
|
|
- DataWriter dw = pub.create_datawriter(top,
|
|
|
+ dw = pub.create_datawriter(top,
|
|
|
qosh.value,
|
|
|
null,
|
|
|
DEFAULT_STATUS_MASK.value);
|
|
@@ -198,10 +202,22 @@ public class DDSPublisher {
|
|
|
isInitialized=false;
|
|
|
running=false;
|
|
|
log.info("终止publisher运行");
|
|
|
-// disconnection();
|
|
|
+ disconnection();
|
|
|
log.info("关闭publisher连接完成");
|
|
|
}
|
|
|
|
|
|
+ private void disconnection() {
|
|
|
+ if (dw != null) {
|
|
|
+ pub.delete_datawriter(dw);
|
|
|
+ }
|
|
|
+ if (pub != null) {
|
|
|
+ dp.delete_publisher(pub);
|
|
|
+ }
|
|
|
+ if (dp != null) {
|
|
|
+ dpf.delete_participant(dp);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
@Bean
|
|
|
@Async
|
|
|
public void processMessageQueue() {
|