How to get the Result from previous activity? - workflow

I am new to WF 4.5.
The "GenerateResult" activity will generate a string in the Result property.
I want to assign the Result to the varExternal in the following Assign activity.
How to?
The GeneratedResult activity is defined as below.
public sealed class GenerateResult<TResult> : NativeActivity<TResult>
{
protected override void Execute(NativeActivityContext context)
{
this.Result.Set(context, "Hello, world!");
}
}

Just like you'd do it when programming. You have to hold the result within a variable, then reference that variable elsewhere.
I'm assuming you want to use the result in the WriteLine activity, so you would create a variable within the workflow (look at the bottom of the designer), bind it to the Result property of your GenerateResult activity (it's in the Property grid, so right-click and hit Properties). Then you can reference that variable in the WriteLine activity.

Related

Reactive mono how to propagate subscription context to `doOnSubscribe` and `doFinally`

I have following aspect that tracks method execution time:
public Object addMetricsToReactiveMonoTimedMethod(ProceedingJoinPoint pjp, ReactiveTimed reactiveTimed) throws Throwable {
StopWatch stopWatch = new StopWatch();
Mono<?> mono = (Mono<?>) pjp.proceed();
return mono
.doOnSubscribe(subscription -> stopWatch.start())
.doFinally(signalType -> {
stopWatch.stop();
logTimer(pjp, stopWatch, reactiveTimed.name(), signalType);
});
}
Method itself looks like that:
public Mono<String> sayHi() {
return Mono.just("hi")
.subscriberContext(context -> context.put("requestId", "requestId"));
}
How can I get requestId variable from subscriber context in my aspect method? I want to use it in doFinally to know which request was profiled.
Disclaimer: I have never used Reactor or anything like it in my whole life. I found this question due to the aspectj tag.
After a quick look at the Mono Javadoc to me it looks like you could just call subscriberContext(Function<Context, Context>) again in the aspect, just like in the target method. You get the existing context as an input parameter for the function or lambda and can do with it what you want. The result of your dummy function/lambda would be a new context, but you can just discard it. I have not tested it, but I mean something like this:
// ...
Mono<?> mono = (Mono<?>) pjp.proceed();
// Alternatively, use a List<Context> with one element, a Stack<Context>, ...
Context[] targetContext = new Context[1];
mono.subscriberContext(context -> {
targetContext[0] = context;
// We can also return null, it does not matter because we are not interested
// in the newly created context, only in the original one we salvaged into the
// outer array.
return context;
});
System.out.println("Now do whatever you need to do with " + targetContext[0]);
// ...
I use a single-element array/list - instead you could "abuse" any other wrapper object such as an atomic reference or a thread-local as a wrapper because you cannot directly assign a to a Context variable from inside the lambda. The code would not compile because the outer variable referenced from inside the lambda needs to be effectively final.

Spring Batch - How to customize Step Exit message description length?

Is there any environment variable or something how to change the maxVarCharLength like tablePrefix in JobRepositoryFactoryBean.java?
I couldn't find any config class where this setter method is called
public void setMaxVarCharLength(int maxVarCharLength) {
this.maxVarCharLength = maxVarCharLength;
}
It is up to you to call this method in order to set the maxVarCharLength property. The JobRepositoryFactoryBean will then use the value you set to create the JobRepository. You can find an example here: https://docs.spring.io/spring-batch/4.0.x/reference/html/job.html#configuringJobRepository

eclipse - Always view object when debugging

I have an object in a Set that has it's guts updated by reference. Is there a way I can use the object hash ID (MyObject#93efa2ed) or Eclipse ID (id=356) to always watch in in my Expressions view even when it's out-of-scope?
I am using Eclipse Neon.
ur question is not quite clear to me, but i guess u mean this:
u have an object O that is contained in a set S, that contains more objects
O is updated in ur code (ie. its internal properties change) and u want to keep an eye on these changes thru the expressions view while u step thru the code
u also want this to happen in code lines/methods that dont a have a straitforward path to O
i dont know of any way (internal eclipse goody) that lets u ref' O by its eclipse debug ID or object hash.
but it can be done fairly simple: u just need to be able to reach O by some (lengthy) way of references from the current frame that is selected in the debugger to accomplish this.
the easiest way is to add some extra code to set O to some static var of some sort.
U can even assign the static var while debugging manually, with the help of the "Display" view that lets u execute java code, that runs in the context of the current stack frame.
Steps:
create/add the class MyWatcher to ur code base.
step thru ur code to where u get ur handle on O (eg. in the sample code, on the 5th break when adding o to the set)
open the Display view and add this line MyWatcher.watches.put("a", o) (replace 'o' by the expression that references O at ur breakpoint)
Execute the line with Ctrl+U or thru the context menu
add this to ur "expressions" view: MyWatcher.watches.get("a")
now O will remain visible at all times, eg. in the example below: even when u are in foo(), b/c the map holds ar ref on O.
public class MyCode {
public static void main(final String[] args) {
bar();
foo();
}
static void bar() {
final Set<Object> set = new HashSet<>();
for (int i = 0; i < 10; i++) {
final List<Integer> o = Arrays.asList(i);
set.add(o);
}
}
static void foo() {
System.out.println("bar");
}
}
public class MyWatcher {
public static final Map<String, Object> watches = new HashMap<>();
}
Add a toString() method in you MyObject class.
You can do it through Eclipse using:
right click(in MyObject) -> Source -> Generate toString().
Now you will be able to see the contents rather than hash id of MyObject.

AS3 - Private Object. Make property as read only

I have a object property in my Class which is private and marked as read-only.
private var readOnlyObj:Object;
I can only access it with a get method:
public function get readOnly(){ return readOnlyObj }
I can access it by:
var objClass = new MyClass();
trace(objClass.readOnly)
And if i'll try to modify it:
objClass.readOnly = new Object();
I'll get an error:
Error# Property is read only.
Now my question is:
How do I set the properties of my readOnlyObj as read-only?
If I have set the object in the constructor:
readOnlyObj["property1"] = 0;
And modify that property by:
objClass.readOnly["property1"] = 2;
It is valid. I want set the property1 to a read-only property. Is this possible? Thank You!
You can do this by returning a duplicate of the original object and not the object itself.
The transform properties of DisplayObjects work like this: you can get the object property from a get function and can modify the object, but such modification has no effect until you pass the modified object back to the set function.
In your case, there's no way to give the object back (no setter) and by returning a copy (commonly called 'clone') from the getter, there is no way to modify the object property from outside, because the returned reference reference the newly created independent clone, essentially making the internal object constant.
What you are asking is not possible and only yield the answer "no" if on the other hand you asked about how to achieve that functionality then there would be a few answer possible.
First of all given your code and the problem at hand it is clear that you misunderstand the class scope. You set:
private var readOnlyObj:Object;
As read only while it's really not the object you want to protect, it's its properties. So readOnlyObj should really not even be visible and accessible.
Now that readOnlyObj is private and not accessible, you can put together a simple method to retrieve properties:
public function getProperty(name:String):*
{
if(readOnlyObj[name] != undefined)
{
return readOnlyObj[name];
}
return null;
}
It might also be useful to know how to put together a public setter that cannot be used externally.
Create an internal Boolean variable (only with true package), then internally set that variable to true before setting the property then set it back to false. Since externally that boolean cannot be set you end up with a public setter that cannot be used externally.
internal var allowSetter:Boolean;
public function set whatever(value:*):void
{
if(allowSetter)
{
//set property ect...
allowSetter = false;
}
}
You can't really do this, at least in the way you describe. You can of course make your readOnly object a custom class instance that only has read-only properties, but you can't freeze a dynamic Object instance.

take the value of outArgument in activity to another activity

By this :
http://msdn.microsoft.com/en-us/library/dd489442.aspx
but the only diffenet that I make the workflow using a XAML file.
I have a qution: i need to pass the value that I got from the user to another activity.
I tried to make a variable (output for example )and assiged the value, but the another activity see it like empty. may its dead or reset to the default value after the current activity finishs.
I tried to use OutArgument, but it make runtime error at app.run as the following
"The following errors were encountered while processing the workflow tree:
'workflow1': The private implementation of activity '1: workflow1' has the following validation error: Value for a required activity argument 'Out_arg' was not supplied."
And also didn't see it in the next activity like the first case.
[RequiredArgument]
public OutArgument<string> Out_arg { get; set; }
void OnBookmarkCallback(NativeActivityContext context, Bookmark bookmark, object val)
{
Console.WriteLine("im in resume ");
Console.WriteLine("bookmark1 Name is {0}", (string)val);
// for the first option that i tried
output = (string)val;
//then i tried
Out_arg.Set(context, (string)val);
the xmal file:
False
270,2.5
60,75
300,77.5 300,107.5 300,129.5
194.5,129.5
211,61
300,190.5 300,220.5 300,279
200,279
200,22
300,301 300,331 280,331 280,389.5
174.5,389.5
211,61
_ReferenceID0
_ReferenceID1
__ReferenceID2
Can u help me?
Did you create variable in you workflow and assign the Out_arg to it?