Add refactored file missed in previous commit
Project: http://git-wip-us.apache.org/repos/asf/ode-jacob/repo Commit: http://git-wip-us.apache.org/repos/asf/ode-jacob/commit/bc93b0e1 Tree: http://git-wip-us.apache.org/repos/asf/ode-jacob/tree/bc93b0e1 Diff: http://git-wip-us.apache.org/repos/asf/ode-jacob/diff/bc93b0e1 Branch: refs/heads/master Commit: bc93b0e192ac967e9af564b1d1c4fa25faf927f8 Parents: f01f92b Author: Hadrian Zbarcea <[email protected]> Authored: Thu Jul 25 20:12:38 2013 -0400 Committer: Hadrian Zbarcea <[email protected]> Committed: Thu Jul 25 20:12:38 2013 -0400 ---------------------------------------------------------------------- .../org/apache/ode/jacob/oo/ProcessUtil.java | 52 ++++++++++++++++++++ 1 file changed, 52 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ode-jacob/blob/bc93b0e1/src/main/java/org/apache/ode/jacob/oo/ProcessUtil.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/ode/jacob/oo/ProcessUtil.java b/src/main/java/org/apache/ode/jacob/oo/ProcessUtil.java new file mode 100644 index 0000000..3be8b82 --- /dev/null +++ b/src/main/java/org/apache/ode/jacob/oo/ProcessUtil.java @@ -0,0 +1,52 @@ +/* + * 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 + * + * 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.apache.ode.jacob.oo; + +import org.apache.ode.jacob.vpu.JacobVPU; + + +public final class ProcessUtil { + private ProcessUtil() { + // Utility class + } + + public static String exportChannel(Channel channel) { + if (channel != null && channel instanceof ChannelProxy) { + // TODO: replace the brute force call on the activeThread with + // something that doesn't expose the implementation once the + // cleaner refactored api becomes available + return JacobVPU.activeJacobThread().exportChannel(channel); + } + throw new IllegalArgumentException("Invalid proxy type: " + + channel == null ? "<null>" : channel.getClass().toString()); + } + + public static CompositeProcess compose(ReceiveProcess process) { + CompositeProcess result = new CompositeProcess(); + return result.or(process); + } + + @SuppressWarnings("serial") + public static <T extends Channel> ChannelListener receive(T proxy, T listener) { + // TODO: NOTE: this *only* works when the listnere doesn't need to be Serialiazble really + // because we cannot declare a staic serialVersionUID like this + // once we fix serialization, this can be simplified significantly via a dsl + return new ReceiveProcess() {}.setChannel(proxy).setReceiver(listener); + } +}
