-
Notifications
You must be signed in to change notification settings - Fork 390
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(plc4j/connection-cache): Added support for subscriptions to the …
…plc connection cache.
- Loading branch information
Showing
5 changed files
with
262 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
.../src/main/java/org/apache/plc4x/java/utils/connectionpool2/CachedSubscriptionRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.plc4x.java.utils.connectionpool2; | ||
|
||
import org.apache.plc4x.java.api.messages.*; | ||
import org.apache.plc4x.java.api.model.PlcSubscriptionTag; | ||
|
||
import java.util.LinkedHashSet; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.concurrent.CompletableFuture; | ||
import java.util.function.Consumer; | ||
|
||
public class CachedSubscriptionRequest implements PlcSubscriptionRequest { | ||
|
||
private final CachedPlcConnection parent; | ||
private final PlcSubscriptionRequest innerRequest; | ||
|
||
public CachedSubscriptionRequest(CachedPlcConnection parent, PlcSubscriptionRequest innerRequest) { | ||
this.parent = parent; | ||
this.innerRequest = innerRequest; | ||
} | ||
|
||
@Override | ||
public CompletableFuture<? extends PlcSubscriptionResponse> execute() { | ||
// Only allowed if connection is still active | ||
return innerRequest.execute(); | ||
} | ||
|
||
@Override | ||
public int getNumberOfTags() { | ||
return innerRequest.getNumberOfTags(); | ||
} | ||
|
||
@Override | ||
public LinkedHashSet<String> getTagNames() { | ||
return innerRequest.getTagNames(); | ||
} | ||
|
||
@Override | ||
public PlcSubscriptionTag getTag(String name) { | ||
return innerRequest.getTag(name); | ||
} | ||
|
||
@Override | ||
public List<PlcSubscriptionTag> getTags() { | ||
return innerRequest.getTags(); | ||
} | ||
|
||
@Override | ||
public Map<String, List<Consumer<PlcSubscriptionEvent>>> getPreRegisteredConsumers() { | ||
return innerRequest.getPreRegisteredConsumers(); | ||
} | ||
|
||
} |
78 changes: 78 additions & 0 deletions
78
...in/java/org/apache/plc4x/java/utils/connectionpool2/CachedSubscriptionRequestBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.plc4x.java.utils.connectionpool2; | ||
|
||
import org.apache.plc4x.java.api.messages.PlcSubscriptionEvent; | ||
import org.apache.plc4x.java.api.messages.PlcSubscriptionRequest; | ||
import org.apache.plc4x.java.api.model.PlcTag; | ||
|
||
import java.time.Duration; | ||
import java.util.function.Consumer; | ||
|
||
public class CachedSubscriptionRequestBuilder implements PlcSubscriptionRequest.Builder { | ||
|
||
private final CachedPlcConnection parent; | ||
private final PlcSubscriptionRequest.Builder builder; | ||
|
||
public CachedSubscriptionRequestBuilder(CachedPlcConnection parent, PlcSubscriptionRequest.Builder builder) { | ||
this.parent = parent; | ||
this.builder = builder; | ||
} | ||
|
||
@Override | ||
public PlcSubscriptionRequest build() { | ||
return builder.build(); | ||
} | ||
|
||
@Override | ||
public PlcSubscriptionRequest.Builder addCyclicTagAddress(String name, String tagAddress, Duration pollingInterval) { | ||
return builder.addCyclicTagAddress(name, tagAddress, pollingInterval); | ||
} | ||
|
||
@Override | ||
public PlcSubscriptionRequest.Builder addCyclicTag(String name, PlcTag tag, Duration pollingInterval) { | ||
return builder.addCyclicTag(name, tag, pollingInterval); | ||
} | ||
|
||
@Override | ||
public PlcSubscriptionRequest.Builder addChangeOfStateTagAddress(String name, String tagAddress) { | ||
return builder.addChangeOfStateTagAddress(name, tagAddress); | ||
} | ||
|
||
@Override | ||
public PlcSubscriptionRequest.Builder addChangeOfStateTag(String name, PlcTag tag) { | ||
return builder.addChangeOfStateTag(name, tag); | ||
} | ||
|
||
@Override | ||
public PlcSubscriptionRequest.Builder addEventTagAddress(String name, String tagAddress) { | ||
return builder.addEventTagAddress(name, tagAddress); | ||
} | ||
|
||
@Override | ||
public PlcSubscriptionRequest.Builder addEventTag(String name, PlcTag tag) { | ||
return builder.addEventTag(name, tag); | ||
} | ||
|
||
@Override | ||
public PlcSubscriptionRequest.Builder addPreRegisteredConsumer(String name, Consumer<PlcSubscriptionEvent> preRegisteredConsumer) { | ||
return builder.addPreRegisteredConsumer(name, preRegisteredConsumer); | ||
} | ||
|
||
} |
46 changes: 46 additions & 0 deletions
46
...rc/main/java/org/apache/plc4x/java/utils/connectionpool2/CachedUnsubscriptionRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.plc4x.java.utils.connectionpool2; | ||
|
||
import org.apache.plc4x.java.api.messages.*; | ||
import org.apache.plc4x.java.api.model.PlcSubscriptionHandle; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
public class CachedUnsubscriptionRequest implements PlcUnsubscriptionRequest { | ||
|
||
private final CachedPlcConnection parent; | ||
private final PlcUnsubscriptionRequest innerRequest; | ||
|
||
public CachedUnsubscriptionRequest(CachedPlcConnection parent, PlcUnsubscriptionRequest innerRequest) { | ||
this.parent = parent; | ||
this.innerRequest = innerRequest; | ||
} | ||
|
||
@Override | ||
public CompletableFuture<PlcUnsubscriptionResponse> execute() { | ||
return innerRequest.execute(); | ||
} | ||
@Override | ||
public List<PlcSubscriptionHandle> getSubscriptionHandles() { | ||
return innerRequest.getSubscriptionHandles(); | ||
} | ||
|
||
} |
59 changes: 59 additions & 0 deletions
59
.../java/org/apache/plc4x/java/utils/connectionpool2/CachedUnsubscriptionRequestBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.plc4x.java.utils.connectionpool2; | ||
|
||
import org.apache.plc4x.java.api.messages.PlcUnsubscriptionRequest; | ||
import org.apache.plc4x.java.api.model.PlcSubscriptionHandle; | ||
import org.apache.plc4x.java.api.model.PlcTag; | ||
|
||
import java.time.Duration; | ||
import java.util.Collection; | ||
import java.util.function.Consumer; | ||
|
||
public class CachedUnsubscriptionRequestBuilder implements PlcUnsubscriptionRequest.Builder { | ||
|
||
private final CachedPlcConnection parent; | ||
private final PlcUnsubscriptionRequest.Builder builder; | ||
|
||
public CachedUnsubscriptionRequestBuilder(CachedPlcConnection parent, PlcUnsubscriptionRequest.Builder builder) { | ||
this.parent = parent; | ||
this.builder = builder; | ||
} | ||
|
||
@Override | ||
public PlcUnsubscriptionRequest build() { | ||
return builder.build(); | ||
} | ||
|
||
@Override | ||
public PlcUnsubscriptionRequest.Builder addHandles(PlcSubscriptionHandle plcSubscriptionHandle) { | ||
return builder.addHandles(plcSubscriptionHandle); | ||
} | ||
|
||
@Override | ||
public PlcUnsubscriptionRequest.Builder addHandles(PlcSubscriptionHandle plcSubscriptionHandle, PlcSubscriptionHandle... plcSubscriptionHandles) { | ||
return builder.addHandles(plcSubscriptionHandle, plcSubscriptionHandles); | ||
} | ||
|
||
@Override | ||
public PlcUnsubscriptionRequest.Builder addHandles(Collection<PlcSubscriptionHandle> plcSubscriptionHandles) { | ||
return builder.addHandles(plcSubscriptionHandles); | ||
} | ||
|
||
} |