...
Code Block |
---|
language | java |
---|
theme | Eclipse |
---|
title | RouteAO |
---|
linenumbers | true |
---|
|
/**********************************************************************************
* Copyright 2011 The Odysseus Team
*
* 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 de.uniol.inf.is.odysseus.core.servertutorial.logicaloperator;
import java.util.LinkedList;
import java.util.List;
import de.uniol.inf.is.odysseus.core.logicaloperator.LogicalOperatorCategory;
import de.uniol.inf.is.odysseus.core.predicate.IPredicate;
import de.uniol.inf.is.odysseus.core.sdf.schema.SDFSchema;
import de.uniol.inf.is.odysseus.core.server.logicaloperator.AbstractLogicalOperator;
import de.uniol.inf.is.odysseus.core.server.logicaloperator.UnaryLogicalOp;
import de.uniol.inf.is.odysseus.core.server.logicaloperator.annotations.LogicalOperator;
import de.uniol.inf.is.odysseus.core.server.logicaloperator.annotations.Parameter;
import de.uniol.inf.is.odysseus.core.server.logicaloperator.builder.BooleanParameter;
import de.uniol.inf.is.odysseus.core.server.logicaloperator.builder.PredicateParameter;
import de.uniol.inf.is.odysseus.core.server.physicaloperator.IHasPredicates;
@LogicalOperator(name = "ROUTE", minInputPorts = 1, maxInputPorts = 1, doc = "This operator can be used to route the elements in the stream to different further processing operators, depending on the predicate.", category = { LogicalOperatorCategory.PROCESSING })
public class RouteAO extends UnaryLogicalOp implements IHasPredicates{
private static final long serialVersionUID = -8015847502104587689L;
private boolean overlappingPredicates = false;
private List<IPredicate<?>> predicates = new LinkedList<IPredicate<?>>();
/**
* if an element is routed to an output, heartbeats will be send to all
* other * other outputs.
*/
private boolean sendingHeartbeats = false;
public RouteAO() {
super();
}
public RouteAO(RouteAO routeAO) {
super(routeAO);
this.overlappingPredicates = routeAO.overlappingPredicates;
this.sendingHeartbeats = routeAO.sendingHeartbeats;
if (routeAO.predicates != null) {
for (IPredicate<?> pred : routeAO.predicates) {
this.predicates.add(pred.clone());
}
}
}
@Override
}
}
}
@Override
protected SDFSchema getOutputSchemaIntern(int pos) {
// since it // since it is a routing, schema is always from input port 0
return super.getOutputSchemaIntern(0);
}
@Parameter(type = PredicateParameter.class, isList = true)
public void setPredicates(List<IPredicate<?>> predicates) {
this.predicates = predicates;
}
@Override
@Override
public List<IPredicate<?>> getPredicates() {
return predicates;
}
@Parameter(name = "overlappingPredicates", type = BooleanParameter.class, optional = true, doc = "Evaluate all (true) or only until first true predicate (false), i.e. deliver to all ports where predicate is true or only to first")
public void setOverlappingPredicates(boolean overlappingPredicates) {
this.overlappingPredicates = overlappingPredicates;
}
@Override
public AbstractLogicalOperator clone() {
return new RouteAO(this);
}
/**
* @return
*/
public boolean isOverlappingPredicates() {
return this. return this.overlappingPredicates;
}
@Parameter(name = "sendingHeartbeats", type = BooleanParameter.class, optional = true, doc = "If an element is routed to an output, heartbeats will be send to all other outputs")
public void setSendingHeartbeats(boolean sendingHeartbeats) {
this.sendingHeartbeats = sendingHeartbeats;
}
public boolean isSendingHeartbeats() {
return this.sendingHeartbeats;
}
}
|
Every operator needs to provide an output schema, i.e. what is the schema of the elements that are produced. As a default implementation AbstractLogicalOperator delivers the input schema as the output schema. Route does not change the input schema, so this implementation is sufficient. If the input schema is not the same as the output schema, the class needs to implement getOutputSchemaIntern(int port), where port is the output port of the operator.
...
To translate the logical operator into the physical counterpart the transformation engine is needed. The rule for the route operator can be found in the following example. Further information can be found in the description of the transformation component. information can be found in the description of the transformation component.
Code Block |
---|
language | java |
---|
theme | Eclipse |
---|
title | TRouteAO |
---|
linenumbers | true |
---|
|
/**********************************************************************************
* Copyright 2011 The Odysseus Team
*
* 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.
*/
|
Code Block |
---|
language | java |
---|
theme | Eclipse |
---|
title | TRouteAO |
---|
linenumbers | true |
---|
|
package de.uniol.inf.is.odysseus.transformtutorial.rules;
import de.uniol.inf.is.odysseus.core.server.logicaloperator.RouteAO;
import de.uniol.inf.is.odysseus.core.server.physicaloperator.RoutePO;
import de.uniol.inf.is.odysseus.core.server.planmanagement.TransformationConfiguration;
import de.uniol.inf.is.odysseus.ruleengine.rule.RuleException;
import de.uniol.inf.is.odysseus.ruleengine.ruleflow.IRuleFlowGroup;
import de.uniol.inf.is.odysseus.transform.flow.TransformRuleFlowGroup;
import de.uniol.inf.is.odysseus.transform.rule.AbstractTransformationRule;
@SuppressWarnings({"unchecked","rawtypes"})
public class TRouteAORule extends AbstractTransformationRule<RouteAO> {
@Override
public int getPriority() {
return 0;
}
@Override
public void execute(RouteAO routeAO, TransformationConfiguration config) throws RuleException {
defaultExecute(routeAO, new RoutePO(routeAO.getPredicates(), routeAO.isOverlappingPredicates(), routeAO.isSendingHeartbeats()), config, true, true);
}
@Override
public boolean isExecutable(RouteAO operator, TransformationConfiguration transformConfig) {
return operator.isAllPhysicalInputSet();
}
@Override
public String getName() {
return "RouteAO -> RoutePO";
}
@Override
public IRuleFlowGroup getRuleFlowGroup() {
return TransformRuleFlowGroup.TRANSFORMATION;
}
@Override
public Class<? super RouteAO> getConditionClass() {
return RouteAO.class;
}
}
|