-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
61c685d
commit 1908f2d
Showing
14 changed files
with
1,201 additions
and
133 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
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
34 changes: 34 additions & 0 deletions
34
rcljava/src/main/java/org/ros2/rcljava/executor/AnyExecutable.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,34 @@ | ||
/* Copyright 2017 Mickael Gaillard <mick.gaillard@gmail.com> | ||
* | ||
* Licensed 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 | ||
* | ||
* http://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.ros2.rcljava.executor; | ||
|
||
import org.ros2.rcljava.node.Node; | ||
import org.ros2.rcljava.node.service.Client; | ||
import org.ros2.rcljava.node.service.Service; | ||
import org.ros2.rcljava.node.topic.Subscription; | ||
import org.ros2.rcljava.time.WallTimer; | ||
|
||
public class AnyExecutable { | ||
|
||
// Only one of the following pointers will be set. | ||
protected Subscription<?> subscription = null; | ||
protected WallTimer timer = null; | ||
protected Service<?> service = null; | ||
protected Client<?> client = null; | ||
|
||
// These are used to keep the scope on the containing items | ||
protected Node node = null; | ||
|
||
} |
117 changes: 117 additions & 0 deletions
117
rcljava/src/main/java/org/ros2/rcljava/executor/BaseThreadedExecutor.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,117 @@ | ||
/* Copyright 2017 Mickael Gaillard <mick.gaillard@gmail.com> | ||
* | ||
* Licensed 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 | ||
* | ||
* http://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.ros2.rcljava.executor; | ||
|
||
import java.util.concurrent.BlockingQueue; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.LinkedBlockingQueue; | ||
|
||
import org.ros2.rcljava.RCLJava; | ||
import org.ros2.rcljava.node.Node; | ||
|
||
public abstract class BaseThreadedExecutor implements ThreadedExecutor { | ||
|
||
protected Object mutex = new Object(); | ||
protected NativeExecutor baseExecutor; | ||
protected volatile ExecutorService executorService; | ||
|
||
protected BlockingQueue<Node> nodes = new LinkedBlockingQueue<Node>(); | ||
|
||
public BaseThreadedExecutor() { | ||
this.baseExecutor = new NativeExecutor(this); | ||
} | ||
|
||
@Override | ||
public void addNode(Node node) { | ||
this.addNode(node, false); | ||
} | ||
|
||
@Override | ||
public void addNode(Node node, boolean notify) { | ||
if (!this.nodes.contains(node)) { | ||
this.nodes.add(node); | ||
|
||
if (notify) { | ||
|
||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void removeNode(Node node) { | ||
this.removeNode(node, false); | ||
} | ||
|
||
@Override | ||
public void removeNode(Node node, boolean notify) { | ||
if (this.nodes.contains(node)) { | ||
this.nodes.remove(node); | ||
|
||
if (notify) { | ||
|
||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void spinSome() { | ||
AnyExecutable anyExecutable = this.baseExecutor.getNextExecutable(); | ||
while (RCLJava.ok() && anyExecutable != null) { | ||
this.baseExecutor.executeAnyExecutable(anyExecutable); | ||
anyExecutable = this.baseExecutor.getNextExecutable(0); | ||
} | ||
|
||
} | ||
|
||
@Override | ||
public void spinOnce(long timeout) { | ||
AnyExecutable anyExecutable = this.baseExecutor.getNextExecutable(timeout); | ||
|
||
if (anyExecutable != null) { | ||
this.baseExecutor.executeAnyExecutable(anyExecutable); | ||
} | ||
} | ||
|
||
@Override | ||
public void spinNodeOnce(Node node, long timeout) { | ||
this.addNode(node, false); | ||
this.spinOnce(timeout); | ||
this.removeNode(node, false); | ||
} | ||
|
||
@Override | ||
public void spinNodeSome(Node node) { | ||
this.addNode(node, false); | ||
this.spinSome(); | ||
this.removeNode(node, false); | ||
} | ||
|
||
@Override | ||
public void run() { | ||
while (RCLJava.ok()) { | ||
synchronized (mutex) { | ||
this.spinOnce(0); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void cancel() { | ||
if (!this.executorService.isShutdown()) { | ||
this.executorService.shutdownNow(); | ||
} | ||
} | ||
|
||
} |
115 changes: 115 additions & 0 deletions
115
rcljava/src/main/java/org/ros2/rcljava/executor/MemoryStrategy.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,115 @@ | ||
/* Copyright 2017 Mickael Gaillard <mick.gaillard@gmail.com> | ||
* | ||
* Licensed 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 | ||
* | ||
* http://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.ros2.rcljava.executor; | ||
|
||
import java.util.concurrent.BlockingQueue; | ||
import java.util.concurrent.ConcurrentLinkedQueue; | ||
|
||
import org.ros2.rcljava.node.Node; | ||
import org.ros2.rcljava.node.service.Client; | ||
import org.ros2.rcljava.node.service.Service; | ||
import org.ros2.rcljava.node.topic.Subscription; | ||
import org.ros2.rcljava.time.WallTimer; | ||
|
||
public class MemoryStrategy { | ||
|
||
public ConcurrentLinkedQueue<Subscription<?>> subscriptionHandles = new ConcurrentLinkedQueue<Subscription<?>>(); | ||
public ConcurrentLinkedQueue<WallTimer> timerHandles = new ConcurrentLinkedQueue<WallTimer>(); | ||
public ConcurrentLinkedQueue<Service<?>> serviceHandles = new ConcurrentLinkedQueue<Service<?>>(); | ||
public ConcurrentLinkedQueue<Client<?>> clientHandles = new ConcurrentLinkedQueue<Client<?>>(); | ||
|
||
public MemoryStrategy() { | ||
|
||
} | ||
|
||
public void clearHandles() { | ||
this.subscriptionHandles.clear(); | ||
this.timerHandles.clear(); | ||
this.serviceHandles.clear(); | ||
this.clientHandles.clear(); | ||
} | ||
|
||
|
||
public boolean collectEntities(final BlockingQueue<Node> nodes) { | ||
for (Node node : nodes) { | ||
for (Subscription<?> subscription : node.getSubscriptions()) { | ||
this.subscriptionHandles.add(subscription); | ||
} | ||
|
||
for (Service<?> service : node.getServices()) { | ||
this.serviceHandles.add(service); | ||
} | ||
|
||
for (Client<?> client : node.getClients()) { | ||
this.clientHandles.add(client); | ||
} | ||
|
||
for (WallTimer timer : node.getWallTimers()) { | ||
this.timerHandles.add(timer); | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* Provide a newly initialized AnyExecutable object. | ||
* @return fresh executable. | ||
*/ | ||
public AnyExecutable instantiateNextExecutable() { | ||
return new AnyExecutable(); | ||
} | ||
|
||
public void getNextSubscription(AnyExecutable anyExecutable, BlockingQueue<Node> nodes) { | ||
Subscription<?> subscription = this.subscriptionHandles.poll(); | ||
if (subscription != null) { | ||
anyExecutable.subscription = subscription; | ||
} | ||
} | ||
|
||
public void getNextService(AnyExecutable anyExecutable, BlockingQueue<Node> nodes) { | ||
Service<?> service = this.serviceHandles.poll(); | ||
if (service != null) { | ||
anyExecutable.service = service; | ||
} | ||
} | ||
|
||
public void getNextClient(AnyExecutable anyExecutable, BlockingQueue<Node> nodes) { | ||
Client<?> client = this.clientHandles.poll(); | ||
if (client != null) { | ||
anyExecutable.client = client; | ||
} | ||
} | ||
|
||
public int numberOfReadySubscriptions() { | ||
return this.subscriptionHandles.size(); | ||
} | ||
|
||
public int numberOfReadyServices() { | ||
return this.serviceHandles.size(); | ||
} | ||
|
||
public int numberOfReadyClients() { | ||
return this.clientHandles.size(); | ||
} | ||
|
||
public int numberOfReadyTimers() { | ||
return this.timerHandles.size(); | ||
} | ||
// public int number_of_guard_conditions() { | ||
// return -1; | ||
// } | ||
|
||
} |
Oops, something went wrong.