I am trying to execute SWF workflow. I am running into an issue regarding state of Promise object. My code strucutre is as below:
Methods in WorkflowClientImpl.java:
#Override
public void doSomething() {
new TryCatch() {
#Override
protected void doTry() throws Throwable {
System.out.println("Workflow Started");
Promise<SomeObject> someObject = activityClient.doAction(param1);
if(someObject.isready()) {
boolean reDo = shouldRestartWorkflow(someObject);
if(reDo) {
Promise<Void> timer = decisionContextProvider.getDecisionContext().getWorkflowClock()
.createTimer(TimeUnit.MINUTES.toSeconds(5));
continueAsNew(timer, param1);
}
}
}
#Override
protected void doCatch(Throwable e) throws Throwable {
System.err.printlnt("Error occured while workflow");
throw new RuntimeException(e);
}
};
}
#Asynchronous
private boolean shouldRestartWorkflow(#Wait Promise<SomeObject> someObject) {
if(someObject.get().getVariable() > 1)
return true;
return false;
}
#Asynchronous
public void continueAsNew(Promise<Void> timer, String param1) {
selfClient.execute(param1);
// SelfClient is instance of TempWorkflowSelfClient
}
The above code is supposed to restart the workflow when certain conditions are met. The conditions are dependent upon values populated in instance of SomeObject returned by activity method. However the code shouldRestartWorkflow never appears to get invoked.
I tried to write a unit test for this. Below is the code:
#Before
public void setUp() throws Exception {
trace = new ArrayList<String>();
// Register activity implementation to be used during test run
TempActivitiesImpl activitiesImpl = new TempActivitiesImpl(null, null) {
#Override
public SomeObject doAction(String randomString) {
trace.add("Test Case - " + randomString);
SomeObject testObject = new SomeObject();
testObject.setVariable(true);
return testObject;
}
};
workflowTest.addActivitiesImplementation(activityImpl); //Instance to activity class
workflowTest.addWorkflowImplementationType(WorkflowImpl.class);
}
#Test
public void testWorkflowExecutionCall() throws Throwable {
WorkflowClient workflow = workflowFactory.getClient("RandomString");
Promise<Void> promise = workflow.execute("RandomString");
List<String> expected = new ArrayList<String>();
expected.add("Test Case - RandomString");
AsyncAssert.assertEqualsWaitFor("Unexpected Result", expected, trace, promise);
}
The above test case works. However if I were to remove the if(someObject.isready()) condition. I get error IllegalStateException: Not Ready. I was able to determine the error occurs when it tries to execute the shouldRestartWorkflow() call.
Am I doing something wrong? As far I understand, the shouldRestartWorkflow() should wait till the SomeObject is populated and returned by activity method before proceeding.
The SWF annotations are not set up properly. Due to this issues #Asynchronous is not working properly.
To add AspectJ as a Java agent
To open the Preferences dialog box, click Window > Preferences.
Navigate to Java > Installed JREs.
Select the appropriate JRE and click Edit.
In the Default VM arguments box, enter the path to the installed
AspectJ binary. This will be a path such as
/home/user/aspectj1.7/lib/aspectjweaver.jar, depending on your
operating system and on the version of AspectJ you downloaded.
On Linux, OS X, or Unix use:
-javaagent:/your_path/aspectj/lib/aspectjweaver.jar
On Windows, use a standard Windows-style path instead:
-javaagent:C:\your_path\aspectj\lib\aspectjweaver.jar
To configure AspectJ for AWS Flow Framework for Java, add an aop.xml file to the project.
To add an aop.xml file
In your project's src directory, add a directory named META-INF.
Add a file named aop.xml to META-INF with the following contents.
<aspectj>
<aspects>
<!-- declare two existing aspects to the weaver -->
<aspect name="com.amazonaws.services.simpleworkflow.flow.aspectj.AsynchronousAspect"/>
<aspect name="com.amazonaws.services.simpleworkflow.flow.aspectj.ExponentialRetryAspect"/>
</aspects>
<weaver options="-verbose">
<include within="<replaceable>MySimpleWorkflow.*</replaceable>"/>
</weaver>
</aspectj>
The value of depends on how you name your project's packages. The above example assumes that the project's packages followed the pattern MySimpleWorkflow.*. Use a value appropriate for your own project's packages.
currently I am working on a plugin for Eclipse CDT.
What I want to achieve:
Prepend a tool (let us call it cov) before the commandline.
gcc -omain.o main.c
should become
cov gcc -omain.o main.c
I tried to write a custom BuildRunner, which extend ExternalBuildrunner, modifies the tools before invoking the external runner. I do this by editing the COmmandLinePattern
So far it works, if I do not restore the old CommandLinePattern.
Is there a way to update configuration to use the modified tools, and later after invocation write the old configurations back.
Before modifiyng, I backup the tool-commandlinepatterns, so that would not be the problem. I am missing the update step here I guess.
public class CovBuildRunner extends ExternalBuildRunner {
private final Set<String> VALUES;
public CovBuildRunner() {
VALUES = new HashSet<String>();
VALUES.add("gcc");
VALUES.add("g++");
}
#Override
public boolean invokeBuild(int kind, IProject project,
IConfiguration configuration, IBuilder builder, IConsole console,
IMarkerGenerator markerGenerator,
IncrementalProjectBuilder projectBuilder, IProgressMonitor monitor)
throws CoreException {
Map<ITool, String> cmdPatternBackup = new HashMap<>();
for (ITool tool : configuration.getTools()) {
if (cmdPatternBackup.containsKey(tool)) {
System.out.println("ERROR! TOOL ALREADY MODIFIED!");
} else if (this.supports(tool)) {
cmdPatternBackup.put(tool, tool.getCommandLinePattern());
tool.setCommandLinePattern("cov " + tool.getCommandLinePattern());
System.out.println(
configuration.getToolCommand(tool));
}
}
configuration.getToolChain().set;
boolean success = invokeExternalBuild(kind, project, configuration, builder, console, markerGenerator, projectBuilder, monitor);
for (ITool tool : cmdPatternBackup.keySet()) {
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("Setting back " + tool.getName() + "\n" + tool.getCommandLinePattern());
tool.setCommandLinePattern(cmdPatternBackup.get(tool));
}
return success;
}
private boolean supports(ITool tool) {
String command = tool.getToolCommand();
return VALUES.contains(command);
}
}
I have a project in Eclipse that has a red cross on it and will not export to a runnable JAR. I can't remember if I have looked at it since I reinstalled Windows on my laptop, but I know that I haven't changed any code. There are no errors in any of the classes, however the error I get points to the following class that deals with the menu items on Mac OSx:
import java.lang.reflect.*;
public class osxhandler implements InvocationHandler {
protected Object targetObject;
protected Method targetMethod;
protected String proxySignature;
static Object macOSXApplication;
// Pass this method an Object and Method equipped to perform application shutdown logic
// The method passed should return a boolean stating whether or not the quit should occur
public static void setQuitHandler(Object target, Method quitHandler) {
setHandler(new HOsx("handleQuit", target, quitHandler));
}
public static void setAboutHandler(Object target, Method aboutHandler) {
boolean enableAboutMenu = (target != null && aboutHandler != null);
if (enableAboutMenu) {
setHandler(new HOsx("handleAbout", target, aboutHandler));
}
// If we're setting a handler, enable the About menu item by calling
// com.apple.eawt.Application reflectively
try {
Method enableAboutMethod = macOSXApplication.getClass().getDeclaredMethod("setEnabledAboutMenu", new Class[] { boolean.class });
enableAboutMethod.invoke(macOSXApplication, new Object[] { Boolean.valueOf(enableAboutMenu) });
} catch (Exception ex) {
System.err.println("MacOSHandler could not access the About Menu");
ex.printStackTrace();
}
}
public static void setPreferencesHandler(Object target, Method prefsHandler) {
boolean enablePrefsMenu = (target != null && prefsHandler != null);
if (enablePrefsMenu) {
setHandler(new HOsx("handlePreferences", target, prefsHandler));
}
// If we're setting a handler, enable the Preferences menu item by calling
// com.apple.eawt.Application reflectively
try {
Method enablePrefsMethod = macOSXApplication.getClass().getDeclaredMethod("setEnabledPreferencesMenu", new Class[] { boolean.class });
enablePrefsMethod.invoke(macOSXApplication, new Object[] { Boolean.valueOf(enablePrefsMenu) });
} catch (Exception ex) {
System.err.println("MacOSHandler could not access the About Menu");
ex.printStackTrace();
}
}
// Pass this method an Object and a Method equipped to handle document events from the Finder
// Documents are registered with the Finder via the CFBundleDocumentTypes dictionary in the
// application bundle's Info.plist
public static void setFileHandler(Object target, Method fileHandler) {
setHandler(new HOsx("handleOpenFile", target, fileHandler) {
// Override MacOSHandler.callTarget to send information on the
// file to be opened
public boolean callTarget(Object appleEvent) {
if (appleEvent != null) {
try {
Method getFilenameMethod = appleEvent.getClass().getDeclaredMethod("getFilename", (Class[])null);
String filename = (String) getFilenameMethod.invoke(appleEvent, (Object[])null);
this.targetMethod.invoke(this.targetObject, new Object[] { filename });
} catch (Exception ex) {
}
}
return true;
}
});
}
// setHandler creates a Proxy object from the passed MacOSHandler and adds it as an ApplicationListener
#SuppressWarnings({ "unchecked", "rawtypes" })
public static void setHandler(HOsx adapter) {
try {
Class applicationClass = Class.forName("com.apple.eawt.Application");
if (macOSXApplication == null) {
macOSXApplication = applicationClass.getConstructor((Class[])null).newInstance((Object[])null);
}
Class applicationListenerClass = Class.forName("com.apple.eawt.ApplicationListener");
Method addListenerMethod = applicationClass.getDeclaredMethod("addApplicationListener", new Class[] { applicationListenerClass });
// Create a proxy object around this handler that can be reflectively added as an Apple ApplicationListener
Object MacOSHandlerProxy = Proxy.newProxyInstance(HOsx.class.getClassLoader(), new Class[] { applicationListenerClass }, adapter);
addListenerMethod.invoke(macOSXApplication, new Object[] { MacOSHandlerProxy });
} catch (ClassNotFoundException cnfe) {
System.err.println("This version of Mac OS X does not support the Apple EAWT. ApplicationEvent handling has been disabled (" + cnfe + ")");
} catch (Exception ex) { // Likely a NoSuchMethodException or an IllegalAccessException loading/invoking eawt.Application methods
System.err.println("Mac OS X Adapter could not talk to EAWT:");
ex.printStackTrace();
}
}
// Each MacOSHandler has the name of the EAWT method it intends to listen for (handleAbout, for example),
// the Object that will ultimately perform the task, and the Method to be called on that Object
protected HOsx(String proxySignature, Object target, Method handler) {
this.proxySignature = proxySignature;
this.targetObject = target;
this.targetMethod = handler;
}
// Override this method to perform any operations on the event
// that comes with the various callbacks
// See setFileHandler above for an example
public boolean callTarget(Object appleEvent) throws InvocationTargetException, IllegalAccessException {
Object result = targetMethod.invoke(targetObject, (Object[])null);
if (result == null) {
return true;
}
return Boolean.valueOf(result.toString()).booleanValue();
}
// InvocationHandler implementation
// This is the entry point for our proxy object; it is called every time an ApplicationListener method is invoked
public Object invoke (Object proxy, Method method, Object[] args) throws Throwable {
if (isCorrectMethod(method, args)) {
boolean handled = callTarget(args[0]);
setApplicationEventHandled(args[0], handled);
}
// All of the ApplicationListener methods are void; return null regardless of what happens
return null;
}
// Compare the method that was called to the intended method when the MacOSHandler instance was created
// (e.g. handleAbout, handleQuit, handleOpenFile, etc.)
protected boolean isCorrectMethod(Method method, Object[] args) {
return (targetMethod != null && proxySignature.equals(method.getName()) && args.length == 1);
}
// It is important to mark the ApplicationEvent as handled and cancel the default behavior
// This method checks for a boolean result from the proxy method and sets the event accordingly
protected void setApplicationEventHandled(Object event, boolean handled) {
if (event != null) {
try {
Method setHandledMethod = event.getClass().getDeclaredMethod("setHandled", new Class[] { boolean.class });
// If the target method returns a boolean, use that as a hint
setHandledMethod.invoke(event, new Object[] { Boolean.valueOf(handled) });
} catch (Exception ex) {
System.err.println("MacOSHandler was unable to handle an ApplicationEvent: " + event);
ex.printStackTrace();
}
}
}
}
Any ideas as to why I can't export/compile? I've never had this issue before.
Just do a clean and/or rebuild on the project.
You can find it under the Project menu of Eclipse.
I also had a different, degenerate case of this problem. Turned out, we had a class in our project that had a file (so Eclipse kept it on the classpath) but no actual class defined in the file (the file only had imports and a class comment... probably a merge gone wrong). Anyway, deleting the file solved the issue.
It’s quite hateful that Eclipse always generates hidden files .project
and .classpath in project folder. Sometimes you’re not aware if
something goes wrong in these files.
After upgrading your Eclipse and if you found the following compile
error, I’d suggest you to check .classpath in your project folder.
The project was not built since its build path is incomplete. Cannot
find the class file for java.lang.Object. Fix the build path then try
building this project
Most likely you would see a line like this.
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/ org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/j2re1.4.2_03"/>
The stupid Eclipse appended this for no reason. Just simply remove it
to make it work again. ;)
/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/j2re1.4.2_xx
Source: http://hochit.com/2006/07/06/eclipse-upgrading-problem-javalangobject-not-found/
In addition, you can check your project settings in eclipse. Right click on your project and choose properties. Go to Java Build Path and there should be more specific information of the problem. Most likely you set the JDK to an Version which doesn't exist on the new System.
If this doesn't help too, select your project and then use the menu entry Source->Clean Up.
In my case, the classes were empty, and the compiler whined:
Class files on classpath not found or not accessible for: 'ibDemo/src/com/ib/controller/LocationCode.java'
Class files on classpath not found or not accessible for: 'ibDemo/src/com/ib/controller/PairPanel.java'
To solve this I'd to add a class declaration:
public class LocationCode
{
}
and
public class PairPanel
{
}
I got referred here, because I had the same error.
I am using maven on eclipse. I did right click on repo, chose build path->Conifgure build->Project References and checked the project references for my repo. This worked for me.
I was also getting the same error. In my case problem was, I had put same jar multiple times once through "user library" & next time through "build path" on the same Project. Just deleted the repeated jars from the classpath & got ride of the above error.
I had the same error and after trying out multiple recommendations, nothing had worked out. So I created a new workspace and refer to this project. After that, it got successfully built and exported the JAR without errors.
Not sure this might be the best possible solution, but do check java build path. I had it pointing to a wrong location because of which I was facing class not found error.
Once java build path was fixed, the problem was resolved.
I came here on same error. In my case, nothing was compiling (building?) and Eclipse didn't tell me there was any issue with the build other than these cryptic messages. I eventually unzipped the jar file and saw that it had no classes in it. It was because because the project I referenced in my build path wasn't built. In my case, the project would not compile in a million years, but I had access to jar files from R&D dept who could and did compile it in their own way. So I referenced those jar files instead. Now my classes compile and the error went away. I'm sure I would have done that in the first place but "Helpful" Eclipse suggested for me to reference the unbuilt project so I went along with the bad suggestion!
I closed all tabs with files in Eclipse, and it's fixed problem.
In my case, I was getting the same problem and I noticed I mvn clean and tried to export the jar and end-up getting the same error.
It worked for me after mvn install.
I am currently developing an Eclipse Plug-In that will let me trigger refactorings, using gestures.
I've been trying to trigger 'extract method' programmatically in Eclipse for a while now but I am constantly running into issues.
Most suggestions I have found while searching for a solution require the use of internal classes.
I am now stuck at this code template. The issue is that I find no place where I could give the code I want to extract as ISelection or something similar.
RefactoringContribution rc = RefactoringCore.getRefactoringContribution(IJavaRefactorings.EXTRACT_METHOD);
ExtractMethodDescriptor rd = (ExtractMethodDescriptor) rc.createDescriptor();
rd.setProject(staticHelper.getIProject().getName());
//There should be some more rd.setXXXXX() here.
RefactoringStatus rs = new RefactoringStatus();
try {
Refactoring r = rd.createRefactoring(rs);
IProgressMonitor pm = new NullProgressMonitor();
r.checkInitialConditions(pm);
r.checkFinalConditions(pm);
Change change = r.createChange(pm);
change.perform(pm);
}
catch(Exception e) {e.printStackTrace();}
}
The following method works, but it uses the internal API:
#SuppressWarnings("restriction") //Works but is INTERNAL USE ONLY
public static void extractMethodRefactoring() {
ITextSelection selection = staticHelper.getITextSelection();
int start = selection.getOffset();
int length = selection.getLength();
//The following line is part of the internal API
ExtractMethodRefactoring tempR = new ExtractMethodRefactoring(staticHelper.getICompilationUnit(), start, length);
try {
NullProgressMonitor pm = new NullProgressMonitor();
tempR.checkAllConditions(pm);
Change change = tempR.createChange(pm);
change.perform(pm);
} catch (Exception e) {e.printStackTrace();}
}
Again this requires the internal class ExtractMethodRefactoring, which should not be used.
trying to integrate gmf with xpand.
I created a menu, and command using extensions in gmf manifest file. and am trying to invoke xpand generator.
The code for the command is as shown below
public class customCommand extends AbstractHandler implements IHandler {
#Override
public Object execute(ExecutionEvent event) throws ExecutionException {
// TODO Auto-generated method stub
Shell s=HandlerUtil.getActiveShell(event);
MessageBox mb=new MessageBox(s,SWT.None);
WorkflowRunner runner = new WorkflowRunner();
Bundle bundle=Platform.getBundle("MistScriptGenerator");
URL wfUrl = bundle.getEntry("src/workflow/generator.oaw");
String wfFile = "";
try {
wfFile = FileLocator.toFileURL(wfUrl).getFile();
mb.setMessage(wfFile);
mb.open();
Map<String, String> properties = new HashMap<String, String>();
//properties.put("model", $diagramFile$.getLocation().toOSString());
properties=null;
boolean isSuccess = runner.run(wfFile,new org.openarchitectureware.workflow.monitor.NullProgressMonito r(), properties, null);
}
catch (Exception e)
{
}
return null;
}
}
I have been able to succesfully get the path for the workflow.
Now while invoking the workflow I will have to input the gmf diagram file, to the workflow. But how can I give the path for the file ?
I execute my gmf digram by opening it another workbench:
But, now, how do i get the path of gmf diagram file ?
I have registered epackage in my workflow.
Can you please guide me the project deadline is very soon.
The IAML project uses openArchitectureWare XPand to implement code generation. As an example of how to connect the two together, you can check out the source code for GenerateCodeAction -- the relevant method is doExecute(). Hope this helps :)