Home › Forums › Business Model › Classes › How to invoke events of a class?
- This topic has 5 replies, 4 voices, and was last updated 8 years, 8 months ago by vi.
-
AuthorPosts
-
-
December 10, 2015 at 9:52 am #461AravinddokalaMember
Hi Team,
What are the different ways to invoke/trigger events of a class?
we wrapped our ‘service’ invocation inside one of the event of Class, we found below xml batch process to invoke the events of class; need info on how to test the same from local environment (using nextJ suite & Tee Server)
123456789101112<?xml version="1.0" encoding="UTF-8"?><BatchProcess><process>TestMyProcess</process><class>TestMyProcessClass</class><event>startMyProcess</event><arguments><argument><name>startMyProcess</name><value>run</value></argument></arguments></BatchProcess>Thanks,
Aravind0 -
December 10, 2015 at 5:07 pm #465AravinddokalaMember
Hi Team,
I found one of the way to invoke events from scratchpad to test as follows:
(TestProcessClass’eventName) ; being eventName should be static and public.Please suggest on how to load ‘BatchProcess xml’ that got mentioned in my above post.
Thanks,
Aravind0-
December 11, 2015 at 1:00 pm #468viParticipant
Please suggest on how to load ‘BatchProcess xml’ that got mentioned in my above post.
If you are using the BatchBrokerFileChannel to submit the message to the service, you just have to set up the directories for the channel in the environment file, and then copy the file with the XML message to the incoming directory. Ideally, it should be done in a way that is similar to the one used by the external system that you are integrating with. One possibility is to use the Scheme I/O APIs, e.g.
(with-output-to-file (string-append ((((invocation-context)'metadata)'getChannel "BatchBrokerFileChannel")'incomingDirectory) "/message" (cast string (cast long (now)))) (lambda (out) (display msg out)))
0
-
-
December 10, 2015 at 5:39 pm #463Ed ShawKeymaster
You’re right. One way to invoke an event on a class is to simply do something like:
(MyClass'myevent arg1 arg2)
The first part of this – MyClass – is a Class. The second part – myevent – is a symbol. The arguments are whatever is expected by the event.
But in your message, you are only passing in strings and the arguments are variable in number, so you will have to go from string to Class, string to symbol and then apply the resulting event to the list of arguments.
If I understand you correctly, I think you want to:
1. specify an xml file that describes a process you want to kick off in the business model. The process, class and event already exist.
2. receive this message over a channel to tell the server to start the process
3. based on this, start the process
So, I’ll assume you are using a file channel, but an HTTP channel or other would work just as well…
1. Create a Message in the integration layer that will allow you to parse your BatchProcess xml structure above.
2. Create a Service to process your message and kick off the process. To start just put a log step in it.
3. Create a File Channel to receive your message and bind it to your service
4. Add the file channel to your environment. Run your server; drop your file in the folder; check your output to see that the message was received.
5. Update your service to do something like the following:
1234567891011121314; parse the message(define msg (parse-message this "MyProcessMessageName")); get the class(define class (((invocation-context)'metadata)'getClassMeta (msg'class))); get the event as a symbol(define event (string->symbol (msg'event))); i'm not going to do it here, but get your arguments into a list in the order that is expected. Likely a way to pass by name too. Maybe someone can chime in with a better way or example; something like (for-each (lambda (i) ; add item to list) (msg'arguments)); invoke the event(apply (class event) argumentList)I hope this helps. Ed
1 -
December 11, 2015 at 1:41 pm #470AravinddokalaMember
Hi Team,
As suggested, I have confugured my BatchBrokerFileChannel and placed the trigger file, that file contains as below:123TestMyProcessTestMyProcessClassstartMyProcessI have started the server, the below was the error received, please suggest:
; 13:39:02,679 ERROR [BatchBrokerService] (NexJ-Worker-17) Event "startMyProcess" on class "TestMyProcess" is not exposed for Batch Broker Service.
Thanks
Aravind0-
December 11, 2015 at 2:42 pm #472viParticipant
Here is how to troubleshoot problems like this one:
1) Find the error code by looking for the message in the *.strings files. In this case, looking for “is not exposed for Batch Broker Service” gives you “err.batchBrokerProcess.notExposed”
2) Find the model file by the error code retrieved in (1). In this case, you find “BatchBrokerService.service”.
3) In the model file, you can see what conditions trigger the error. In this case, it cannot find an instance of BatchBrokerProcess by class name and event name. The batch broker has to be configured with such an entry. One way of doing that is (re-)creating the entries in a persistence initializer (class that has the aspect PERSISTENCE_INITIALIZER and implements actions in the initializePersistence event).
0
-
-
-
AuthorPosts
- You must be logged in to reply to this topic.