Skip to content

Commit

Permalink
Added coordinatorRole and memberRole fields into the EnsembleDefinition
Browse files Browse the repository at this point in the history
lass. + tests + appropriate changes in AnnotationProcessor.

Processes/memberships/knowledge exchanges with zero parameters are
enabled from now on.
  • Loading branch information
jiracekz committed Mar 4, 2015
1 parent 186a19c commit 48a53b0
Show file tree
Hide file tree
Showing 12 changed files with 338 additions and 33 deletions.
2 changes: 2 additions & 0 deletions jdeeco-core/model/RuntimeModel.ecore
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@
<eStructuralFeatures xsi:type="ecore:EAttribute" name="communicationBoundary"
eType="#//CommunicationBoundary"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="partitionedBy" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="coordinatorRole" eType="#//Type"/>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="memberRole" eType="#//Type"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Condition" eSuperTypes="#//Invocable"/>
<eClassifiers xsi:type="ecore:EClass" name="Exchange" eSuperTypes="#//Invocable"/>
Expand Down
10 changes: 9 additions & 1 deletion jdeeco-core/model/RuntimeModel.ecorediag
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,14 @@
<element xmi:type="ecore:EAttribute" href="RuntimeModel.ecore#//EnsembleDefinition/partitionedBy"/>
<layoutConstraint xmi:type="notation:Location" xmi:id="_vP7cwGTyEeSotbgE2UC1AQ"/>
</children>
<children xmi:type="notation:Node" xmi:id="_QmJZgMKIEeSrO9KScWtpWg" type="2001">
<element xmi:type="ecore:EAttribute" href="RuntimeModel.ecore#//EnsembleDefinition/coordinatorRole"/>
<layoutConstraint xmi:type="notation:Location" xmi:id="_QmJZgcKIEeSrO9KScWtpWg"/>
</children>
<children xmi:type="notation:Node" xmi:id="_W1nzgMKIEeSrO9KScWtpWg" type="2001">
<element xmi:type="ecore:EAttribute" href="RuntimeModel.ecore#//EnsembleDefinition/memberRole"/>
<layoutConstraint xmi:type="notation:Location" xmi:id="_W1nzgcKIEeSrO9KScWtpWg"/>
</children>
<styles xmi:type="notation:DrawerStyle" xmi:id="_V0Kr4j28EeO2QcBZHbiySQ"/>
<styles xmi:type="notation:SortingStyle" xmi:id="_V0Kr4z28EeO2QcBZHbiySQ"/>
<styles xmi:type="notation:FilteringStyle" xmi:id="_V0Kr5D28EeO2QcBZHbiySQ"/>
Expand All @@ -188,7 +196,7 @@
</children>
<styles xmi:type="notation:ShapeStyle" xmi:id="_V0KE0T28EeO2QcBZHbiySQ" fontColor="4210752" fontName="Segoe UI" fontHeight="10" fillColor="13761016" lineColor="8421504"/>
<element xmi:type="ecore:EClass" href="RuntimeModel.ecore#//EnsembleDefinition"/>
<layoutConstraint xmi:type="notation:Bounds" xmi:id="_V0KE0j28EeO2QcBZHbiySQ" x="675" y="648" height="99"/>
<layoutConstraint xmi:type="notation:Bounds" xmi:id="_V0KE0j28EeO2QcBZHbiySQ" x="672" y="624" height="123"/>
</children>
<children xmi:type="notation:Node" xmi:id="_bcRj4D28EeO2QcBZHbiySQ" type="1001">
<children xmi:type="notation:Node" xmi:id="_bcSK8D28EeO2QcBZHbiySQ" type="4001"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,19 @@ EnsembleDefinition createEnsembleDefinition(Class<?> clazz) throws AnnotationPro
CommunicationBoundaryPredicate cBoundary = createCommunicationBoundary(clazz);
ensembleDefinition.setCommunicationBoundary(cBoundary);

// take the first role (if exists)
// at current setting, it is not possible to have multiple instances of the same annotation
// and if it would be possible, it is checked in RolesAnnotationChecker
Class<?>[] coordinatorRoleAnnotations = RoleAnnotationsHelper.getCoordinatorRoleAnnotations(clazz);
if (coordinatorRoleAnnotations != null && coordinatorRoleAnnotations.length > 0) {
ensembleDefinition.setCoordinatorRole(coordinatorRoleAnnotations[0]);
}

Class<?>[] memberRoleAnnotations = RoleAnnotationsHelper.getMemberRoleAnnotations(clazz);
if (memberRoleAnnotations != null && memberRoleAnnotations.length > 0) {
ensembleDefinition.setMemberRole(memberRoleAnnotations[0]);
}

TimeTrigger periodicEnsembleTrigger = createPeriodicTrigger(clazz);
List<KnowledgeChangeTrigger> exchangeKChangeTriggers = createKnowledgeChangeTriggers(exchange.getMethod(), PathOrigin.ENSEMBLE);
List<KnowledgeChangeTrigger> conditionKChangeTriggers = createKnowledgeChangeTriggers(condition.getMethod(), PathOrigin.ENSEMBLE);
Expand Down Expand Up @@ -961,10 +974,7 @@ List<Parameter> createParameters(Method method, PathOrigin pathOrigin)
for (int i = 0; i < parameterTypes.length; i++) {
parameters.add(createParameter(parameterTypes[i], genericTypes[i], i, allAnnotations[i], pathOrigin));
}
if (parameters.isEmpty()) {
throw new AnnotationProcessorException(
"The "+ (pathOrigin == PathOrigin.COMPONENT ? "component" : "ensemble") + " process cannot have zero parameters.");
}

return parameters;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*
*/
public class RoleAnnotationsHelper {

public static Class<?>[] getCoordinatorRoleAnnotations(Class<?> clazz) {
Class<?>[] result = translateCoordinatorRoles(clazz.getAnnotationsByType(CoordinatorRole.class));
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import cz.cuni.mff.d3s.deeco.network.CommunicationBoundaryPredicate;

import java.lang.reflect.Type;
import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EObject;
Expand All @@ -22,6 +23,8 @@
* <li>{@link cz.cuni.mff.d3s.deeco.model.runtime.api.EnsembleDefinition#getTriggers <em>Triggers</em>}</li>
* <li>{@link cz.cuni.mff.d3s.deeco.model.runtime.api.EnsembleDefinition#getCommunicationBoundary <em>Communication Boundary</em>}</li>
* <li>{@link cz.cuni.mff.d3s.deeco.model.runtime.api.EnsembleDefinition#getPartitionedBy <em>Partitioned By</em>}</li>
* <li>{@link cz.cuni.mff.d3s.deeco.model.runtime.api.EnsembleDefinition#getCoordinatorRole <em>Coordinator Role</em>}</li>
* <li>{@link cz.cuni.mff.d3s.deeco.model.runtime.api.EnsembleDefinition#getMemberRole <em>Member Role</em>}</li>
* </ul>
* </p>
*
Expand Down Expand Up @@ -176,4 +179,56 @@ public interface EnsembleDefinition extends EObject {
*/
void setPartitionedBy(String value);

/**
* Returns the value of the '<em><b>Coordinator Role</b></em>' attribute.
* <!-- begin-user-doc -->
* <p>
* If the meaning of the '<em>Coordinator Role</em>' attribute isn't clear,
* there really should be more of a description here...
* </p>
* <!-- end-user-doc -->
* @return the value of the '<em>Coordinator Role</em>' attribute.
* @see #setCoordinatorRole(Type)
* @see cz.cuni.mff.d3s.deeco.model.runtime.meta.RuntimeMetadataPackage#getEnsembleDefinition_CoordinatorRole()
* @model dataType="cz.cuni.mff.d3s.deeco.model.runtime.api.Type"
* @generated
*/
Type getCoordinatorRole();

/**
* Sets the value of the '{@link cz.cuni.mff.d3s.deeco.model.runtime.api.EnsembleDefinition#getCoordinatorRole <em>Coordinator Role</em>}' attribute.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @param value the new value of the '<em>Coordinator Role</em>' attribute.
* @see #getCoordinatorRole()
* @generated
*/
void setCoordinatorRole(Type value);

/**
* Returns the value of the '<em><b>Member Role</b></em>' attribute.
* <!-- begin-user-doc -->
* <p>
* If the meaning of the '<em>Member Role</em>' attribute isn't clear,
* there really should be more of a description here...
* </p>
* <!-- end-user-doc -->
* @return the value of the '<em>Member Role</em>' attribute.
* @see #setMemberRole(Type)
* @see cz.cuni.mff.d3s.deeco.model.runtime.meta.RuntimeMetadataPackage#getEnsembleDefinition_MemberRole()
* @model dataType="cz.cuni.mff.d3s.deeco.model.runtime.api.Type"
* @generated
*/
Type getMemberRole();

/**
* Sets the value of the '{@link cz.cuni.mff.d3s.deeco.model.runtime.api.EnsembleDefinition#getMemberRole <em>Member Role</em>}' attribute.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @param value the new value of the '<em>Member Role</em>' attribute.
* @see #getMemberRole()
* @generated
*/
void setMemberRole(Type value);

} // EnsembleDefinition
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
*/
package cz.cuni.mff.d3s.deeco.model.runtime.api;

import java.lang.reflect.Type;
import org.eclipse.emf.ecore.EObject;

/**
Expand Down Expand Up @@ -142,12 +143,12 @@ public interface Parameter extends EObject {
* </p>
* <!-- end-user-doc -->
* @return the value of the '<em>Generic Type</em>' attribute.
* @see #setGenericType(java.lang.reflect.Type)
* @see #setGenericType(Type)
* @see cz.cuni.mff.d3s.deeco.model.runtime.meta.RuntimeMetadataPackage#getParameter_GenericType()
* @model dataType="cz.cuni.mff.d3s.deeco.model.runtime.api.Type" required="true"
* @generated
*/
java.lang.reflect.Type getGenericType();
Type getGenericType();

/**
* Sets the value of the '{@link cz.cuni.mff.d3s.deeco.model.runtime.api.Parameter#getGenericType <em>Generic Type</em>}' attribute.
Expand All @@ -157,6 +158,6 @@ public interface Parameter extends EObject {
* @see #getGenericType()
* @generated
*/
void setGenericType(java.lang.reflect.Type value);
void setGenericType(Type value);

} // Parameter
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import cz.cuni.mff.d3s.deeco.network.CommunicationBoundaryPredicate;

import java.lang.reflect.Type;
import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;
Expand Down Expand Up @@ -40,6 +41,8 @@
* <li>{@link cz.cuni.mff.d3s.deeco.model.runtime.impl.EnsembleDefinitionImpl#getTriggers <em>Triggers</em>}</li>
* <li>{@link cz.cuni.mff.d3s.deeco.model.runtime.impl.EnsembleDefinitionImpl#getCommunicationBoundary <em>Communication Boundary</em>}</li>
* <li>{@link cz.cuni.mff.d3s.deeco.model.runtime.impl.EnsembleDefinitionImpl#getPartitionedBy <em>Partitioned By</em>}</li>
* <li>{@link cz.cuni.mff.d3s.deeco.model.runtime.impl.EnsembleDefinitionImpl#getCoordinatorRole <em>Coordinator Role</em>}</li>
* <li>{@link cz.cuni.mff.d3s.deeco.model.runtime.impl.EnsembleDefinitionImpl#getMemberRole <em>Member Role</em>}</li>
* </ul>
* </p>
*
Expand Down Expand Up @@ -136,6 +139,46 @@ public class EnsembleDefinitionImpl extends MinimalEObjectImpl.Container impleme
*/
protected String partitionedBy = PARTITIONED_BY_EDEFAULT;

/**
* The default value of the '{@link #getCoordinatorRole() <em>Coordinator Role</em>}' attribute.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see #getCoordinatorRole()
* @generated
* @ordered
*/
protected static final Type COORDINATOR_ROLE_EDEFAULT = null;

/**
* The cached value of the '{@link #getCoordinatorRole() <em>Coordinator Role</em>}' attribute.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see #getCoordinatorRole()
* @generated
* @ordered
*/
protected Type coordinatorRole = COORDINATOR_ROLE_EDEFAULT;

/**
* The default value of the '{@link #getMemberRole() <em>Member Role</em>}' attribute.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see #getMemberRole()
* @generated
* @ordered
*/
protected static final Type MEMBER_ROLE_EDEFAULT = null;

/**
* The cached value of the '{@link #getMemberRole() <em>Member Role</em>}' attribute.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @see #getMemberRole()
* @generated
* @ordered
*/
protected Type memberRole = MEMBER_ROLE_EDEFAULT;

/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
Expand Down Expand Up @@ -316,6 +359,48 @@ public void setPartitionedBy(String newPartitionedBy) {
eNotify(new ENotificationImpl(this, Notification.SET, RuntimeMetadataPackage.ENSEMBLE_DEFINITION__PARTITIONED_BY, oldPartitionedBy, partitionedBy));
}

/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public Type getCoordinatorRole() {
return coordinatorRole;
}

/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public void setCoordinatorRole(Type newCoordinatorRole) {
Type oldCoordinatorRole = coordinatorRole;
coordinatorRole = newCoordinatorRole;
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET, RuntimeMetadataPackage.ENSEMBLE_DEFINITION__COORDINATOR_ROLE, oldCoordinatorRole, coordinatorRole));
}

/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public Type getMemberRole() {
return memberRole;
}

/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @generated
*/
public void setMemberRole(Type newMemberRole) {
Type oldMemberRole = memberRole;
memberRole = newMemberRole;
if (eNotificationRequired())
eNotify(new ENotificationImpl(this, Notification.SET, RuntimeMetadataPackage.ENSEMBLE_DEFINITION__MEMBER_ROLE, oldMemberRole, memberRole));
}

/**
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
Expand Down Expand Up @@ -354,6 +439,10 @@ public Object eGet(int featureID, boolean resolve, boolean coreType) {
return getCommunicationBoundary();
case RuntimeMetadataPackage.ENSEMBLE_DEFINITION__PARTITIONED_BY:
return getPartitionedBy();
case RuntimeMetadataPackage.ENSEMBLE_DEFINITION__COORDINATOR_ROLE:
return getCoordinatorRole();
case RuntimeMetadataPackage.ENSEMBLE_DEFINITION__MEMBER_ROLE:
return getMemberRole();
}
return super.eGet(featureID, resolve, coreType);
}
Expand Down Expand Up @@ -386,6 +475,12 @@ public void eSet(int featureID, Object newValue) {
case RuntimeMetadataPackage.ENSEMBLE_DEFINITION__PARTITIONED_BY:
setPartitionedBy((String)newValue);
return;
case RuntimeMetadataPackage.ENSEMBLE_DEFINITION__COORDINATOR_ROLE:
setCoordinatorRole((Type)newValue);
return;
case RuntimeMetadataPackage.ENSEMBLE_DEFINITION__MEMBER_ROLE:
setMemberRole((Type)newValue);
return;
}
super.eSet(featureID, newValue);
}
Expand Down Expand Up @@ -416,6 +511,12 @@ public void eUnset(int featureID) {
case RuntimeMetadataPackage.ENSEMBLE_DEFINITION__PARTITIONED_BY:
setPartitionedBy(PARTITIONED_BY_EDEFAULT);
return;
case RuntimeMetadataPackage.ENSEMBLE_DEFINITION__COORDINATOR_ROLE:
setCoordinatorRole(COORDINATOR_ROLE_EDEFAULT);
return;
case RuntimeMetadataPackage.ENSEMBLE_DEFINITION__MEMBER_ROLE:
setMemberRole(MEMBER_ROLE_EDEFAULT);
return;
}
super.eUnset(featureID);
}
Expand All @@ -440,6 +541,10 @@ public boolean eIsSet(int featureID) {
return COMMUNICATION_BOUNDARY_EDEFAULT == null ? communicationBoundary != null : !COMMUNICATION_BOUNDARY_EDEFAULT.equals(communicationBoundary);
case RuntimeMetadataPackage.ENSEMBLE_DEFINITION__PARTITIONED_BY:
return PARTITIONED_BY_EDEFAULT == null ? partitionedBy != null : !PARTITIONED_BY_EDEFAULT.equals(partitionedBy);
case RuntimeMetadataPackage.ENSEMBLE_DEFINITION__COORDINATOR_ROLE:
return COORDINATOR_ROLE_EDEFAULT == null ? coordinatorRole != null : !COORDINATOR_ROLE_EDEFAULT.equals(coordinatorRole);
case RuntimeMetadataPackage.ENSEMBLE_DEFINITION__MEMBER_ROLE:
return MEMBER_ROLE_EDEFAULT == null ? memberRole != null : !MEMBER_ROLE_EDEFAULT.equals(memberRole);
}
return super.eIsSet(featureID);
}
Expand All @@ -460,6 +565,10 @@ public String toString() {
result.append(communicationBoundary);
result.append(", partitionedBy: ");
result.append(partitionedBy);
result.append(", coordinatorRole: ");
result.append(coordinatorRole);
result.append(", memberRole: ");
result.append(memberRole);
result.append(')');
return result.toString();
}
Expand Down
Loading

0 comments on commit 48a53b0

Please sign in to comment.