| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#1
| |||
| |||
| I am trying to make the Java code happen at the following URL using BSF4REXX. The trouble I have is adding the event listener. https://rome.dev.java.net/source/bro...va?view=markup The java code in question looks like this (similar to the prior FeedReader code but with a listener): URL feedUrl = new URL(args[0]); FeedFetcherCache feedInfoCache = HashMapFeedInfoCache.getInstance(); FeedFetcher fetcher = new HttpURLFeedFetcher(feedInfoCache); FetcherEventListenerImpl listener = new FetcherEventListenerImpl(); fetcher.addFetcherEventListener(listener); System.err.println("Retrieving feed " + feedUrl); // Retrieve the feed. // We will get a Feed Polled Event and then a // Feed Retrieved event (assuming the feed is valid) SyndFeed feed = fetcher.retrieveFeed(feedUrl); Java solves the issue by adding: FetcherEventListenerImpl implements FetcherListener In REXX I seem to have to use: fetcher~bsf.addEventListener with some parameters. What would the parameters look like in this case? Iget IllegalArgumentException with everything I tried. I am not clear about the eventSetName. The eventName seem to be the static fields from FetcherEvent, i.e. polled, retrieved, unchanged. I assume that the eventText is what gets passed back to REXX from the bsf("pollEventText") method. From the parameters, I assume that I cannot implement the FetcherListener similar to Java as a thread/process. Any help would be greatly appreciated. |
|
#2
| |||
| |||
| Hi Raetus, regli wrote: > I am trying to make the Java code happen at the following URL using > BSF4REXX. The trouble I have is adding the event listener. > > https://rome.dev.java.net/source/bro...va?view=markup > > The java code in question looks like this (similar to the prior > FeedReader code but with a listener): > > URL feedUrl = new URL(args[0]); > FeedFetcherCache feedInfoCache = HashMapFeedInfoCache.getInstance(); > FeedFetcher fetcher = new HttpURLFeedFetcher(feedInfoCache); > > FetcherEventListenerImpl listener = new FetcherEventListenerImpl(); > > fetcher.addFetcherEventListener(listener); > > System.err.println("Retrieving feed " + feedUrl); > // Retrieve the feed. > // We will get a Feed Polled Event and then a > // Feed Retrieved event (assuming the feed is valid) > SyndFeed feed = fetcher.retrieveFeed(feedUrl); > > Java solves the issue by adding: > FetcherEventListenerImpl implements FetcherListener > > In REXX I seem to have to use: > fetcher~bsf.addEventListener with some parameters. > > > What would the parameters look like in this case? Iget > IllegalArgumentException with everything I tried. > I am not clear about the eventSetName. The eventName seem to be the > static fields from FetcherEvent, i.e. polled, retrieved, unchanged. I > assume that the eventText is what gets passed back to REXX from the > bsf("pollEventText") method. > > From the parameters, I assume that I cannot implement the > FetcherListener similar to Java as a thread/process. > > Any help would be greatly appreciated. Currently, ooRexx does not really allow for calling back into a running program. Therefore Java events would be collected on the Java side and for every event that occurred, the appropriate event text [as submitted in bsf.addEventListener()] will be put into an event queue. Upon return to the Rexx side you can test and poll those event texts by issuing a "bsf.pollEventText()", which has an optional argument (timeout in milli seconds). Without an argument this call won't return until an event text gets put into the text event queue by the Java side (actually the appropriate peer BSF Java event adapter). With an argument the call returns after the given amount of msecs and if no event text has been put into the event queue, then .nil (in classic Rexx the string '.NIL') will be the return value to indicate that no event text was returned. So what you need at the moment is an event loop on the Rexx side to fetch and process the event texts that get put into the event queue at tha Java side each time a Java event occurs for which an event adapter got defined. You find examples for this in the "samples" directory of BSF4Rexx where all of the GUI samples depend on the proper event handling of Java events. --- Ad event adapter: The event adapter invocation expects three arguments: - the name of the event class, in your case probably "fetcher" (this name is built by removing the trailing "Listener"), - the name of an event in the listener (the name of any of the event methods) where the case of this string matters; if you supply an empty string, then all events of that listener will be processed - the event text you wish to be sent to you via the event queue, whenever the event gets processed on the Java side (in my examples the event text represents actually Rexx code such that it can be directly interpreted) So, given your information and your ooRexx snippet, maybe the following works for you: fetcher~bsf.addEventListener("fetcher", "", "say 'got an event from the FetcherListener'") ... the above would process any event from the FetcherListener type or maybe fetcher~bsf.addEventListener("fetcher", "polled", "say '-> got a 'polled' event'") ... the above would process the "polled" event from the FetcherListener type Please note: - the case of the event strings *is* (currently) significant, - you may add multiple event listeners to the same Java object, - you can use the event text queue for other purposes as well [cf. bsf.postEventText(), there are three priority levels there, "0"=batch, "1"=normal, "2"=high; polling of text events starts at the highest level and goes down to batch level, if the higher queues were/became empty] --- A last remark: - there is a new BSF4Rexx "boiling" in which event adapters become able to process the event names case independently; also, it becomes possible in the second argument to denote multiple, blank-delimited events, such that one could define a subset of events that a particular event adapter should process. That version will go into a small beta-phase (as it happens, probably sometimes today, Central European Time) before making it broadly available. HTH, ---rony |
|
#3
| |||
| |||
| rony, Thank you very much for your input. I have the following code (not cleaned up yet as I am simply trying to get things to work): feedUrl = .bsf~new("java.net.URL", inURL) FetcherEvent = bsf.loadClass("com.sun.syndication.fetcher.Fetcher Event") feedInfoCache = bsf.loadClass("com.sun.syndication.fetcher.impl.Fe edFetcherCache") HashMapFeedInfoCache = bsf.loadClass("com.sun.syndication.fetcher.impl.Ha shMapFeedInfoCache") feedInfoCache = HashMapFeedInfoCache~getInstance() fetcher = .bsf~new("com.sun.syndication.fetcher.impl.HttpURL FeedFetcher",feedInfoCache) EVENT_TYPE_FEED_RETRIEVED = .bsf~bsf.getStaticValue("com.sun.syndication.fetch er.FetcherEvent","EVENT_TYPE_FEED_RETRIEVED") EVENT_TYPE_FEED_POLLED = .bsf~bsf.getStaticValue("com.sun.syndication.fetch er.FetcherEvent","EVENT_TYPE_FEED_POLLED") EVENT_TYPE_FEED_UNCHANGED = .bsf~bsf.getStaticValue("com.sun.syndication.fetch er.FetcherEvent","EVENT_TYPE_FEED_UNCHANGED") fetcher~bsf.addEventListener("fetcher",value(EVENT _TYPE_FEED_RETRIEVED),'say "event retrieved"') The addEventListener method fails with: REXX-ooRexx_3.2.0(MT) 6.02 30 Oct 2007 - Java Version: 1.6.0_06 java.lang.IllegalArgumentException: event set 'com.sun.syndication.fetcher.impl.HttpURLFeedFetch er@14693c7' unknown for source type 'class com.sun.syndication.fetcher.impl.HttpURLFeedFetche r' aorg.apache.bsf.util.ReflectionUtils.addEventListe ner(ReflectionUtils.java: 92) aorg.apache.bsf.util.EngineUtils.addEventListener( EngineUtils.java: 96) aorg.rexxla.bsf.engines.rexx.RexxAndJava.javaCallB SF(RexxAndJava.java: 1611) BSF4Rexx subfunction "addEventListener": could not add 'eventText', got BSF exception: [EngineUtils.addEventListener()] ouch while adding event listener: java.lang.IllegalArgumentException: event set 'com.sun.syndication.fetcher.impl.HttpURLFeedFetch er@14693c7' unknown for source type 'class com.sun.syndication. java.lang.IllegalArgumentException: event set 'com.sun.syndication.fetcher.impl.HttpURLFeedFetch er@14693c7' unknown for source type 'class com.sun.syndication.fetcher.impl.HttpURLFeedFetche r' aorg.apache.bsf.util.ReflectionUtils.addEventListe ner(ReflectionUtils.java: 92) aorg.apache.bsf.util.EngineUtils.addEventListenerR eturningEventInfos(EngineUtils.java: 154) aorg.rexxla.bsf.engines.rexx.RexxAndJava.javaCallB SF(RexxAndJava.java: 1663) BSF4Rexx subfunction "addEventListener": could not add 'eventText', got BSF exception: [EngineUtils.addEventListenerReturningEventInfos()] ouch while adding event listener: java.lang.IllegalArgumentException: event set 'com.sun.syndication.fetcher.impl.HttpURLFeedFetch er@14693c7' unknown for source type 'class c org.apache.bsf.BSFException: BSF4Rexx subfunction "addEventListener" componentType [com.sun.syndication.fetcher.impl.HttpURLFeedFetche r@14693c7] is not an instance of 'Class'! aorg.rexxla.bsf.engines.rexx.RexxAndJava.javaCallB SF(RexxAndJava.java: 1690) Note that if I use the following code: fetcher~bsf.addEventListener(fetcher,"",'say "event retrieved"') that it terminates ungracefully. |
|
#4
| |||
| |||
| Hi Raetus, > java.lang.IllegalArgumentException: event set > 'com.sun.syndication.fetcher.impl.HttpURLFeedFetch er@14693c7' unknown > for source type 'class > com.sun.syndication.fetcher.impl.HttpURLFeedFetche r' This means that the introspection of the class 'com.sun.syndication.fetcher.impl.HttpURLFeedFetch er' did not yield information about events that class fires. Are you sure that this class indeed does fire events at all? Could it be that the Java example is not working? What does a "javap -public com.sun.syndication.fetcher.impl.HttpURLFeedFetche r" list? Here is a quick transcription (which would cause the same error that you report): ------------ cut here -------------- /* cf. <news:comp.lang.rexx> posting of Raetus on 2008-06-18 Java source: <https://rome.dev.java.net/source/browse/rome/subprojects/fetcher/src/java/com/sun/syndication/fetcher/samples/FeedReader.java?view=markup> */ /* needs: - ROME, <https://rome.dev.java.net/> states as of 2008-06-05: "ROME is an set of open source Java tools for parsing, generating and publishing RSS and Atom feeds. The core ROME library depends only on the JDOM XML parser and supports parsing, generating and converting all of the popular RSS and Atom formats including RSS 0.90, RSS 0.91 Netscape, RSS 0.91 Userland, RSS 0.92, RSS 0.93, RSS 0.94, RSS 1.0, RSS 2.0, Atom 0.3, and Atom 1.0. You can parse to an RSS object model, an Atom object model or an abstract SyndFeed model that can model either family of formats." - JDOM, <http://jdom.org> example: testFeedReader http://ooonewsletter.blogspot.com/atom.xml */ parse arg url test=bsf.import("com.sun.syndication.fetcher.Fetch erListener", "FetcherListener") feedUrl = .bsf~new("java.net.URL", url) -- create a Java URL object feedUrlString= feedUrl~toString feedInfoCache= bsf.loadClass("com.sun.syndication.fetcher.impl.Ha shMapFeedInfoCache")~getInstance fetcher = .bsf~new("com.sun.syndication.fetcher.impl.HttpURL FeedFetcher", feedInfoCache) fetcher~bsf.addEventListener("fetcher", "", "say 'a fetcher event occured'") fetcher~bsf.addEventListener("fetcher", "unchanged", "say 'an ''unchanged'' fetcher event occured'") fetcher~bsf.addEventListener("fetcher", "polled", "say 'a ''polled'' fetcher event occured'") fetcher~bsf.addEventListener("fetcher", "retrieved", "say 'a ''retrieved'' fetcher event occured'") ..error~say("Retrieving feed" feedUrlString) feed = fetcher~retrieveFeed(feedUrl) ..error~say(feedUrlString "retrieved") ..error~say(feedUrlString "has a title:" feed~getTitle "and contains" feed~getEntries~size - "entries.") ..error~say("Polling" feedUrlString "again to test conditional get support.") feed2 = fetcher~retrieveFeed(feedUrl) do forever /* this is our event loop, processing event texts */ evText=bsf.pollEventText(10) /* get event text, timeout value 10/1000 secs */ say "evText:" pp(evText) if evText=.nil then leave /* no event text, leave event loop */ end ..error~say('If a "Feed Unchanged" event fired then the server supports conditional gets.') exit 0 ::requires bsf.cls -- get Java support for ooRexx ------------ cut here -------------- Am a little bit in a hurry to get home, so I need to stop for the moment, but maybe you could look into that in the meantime? --- Here is the beta of the latest drop of BSF4Rexx: <http://wi.wu-wien.ac.at/rgf/rexx/bsf4rexx/old/2008/dist.20080618/>. Make sure that you de-install your current version before installing the new one (from the installation zip archive). Please note that the reference cards (the PDF files) were updated as well. HTH, ---rony |
|
#5
| |||
| |||
| rony, I am simply impressed by your helpfulness. Thanks again. > Are you sure that this class indeed does fire events at all? Could it be that the Java example is > not working? I just tested the FeedReader sample in Eclipse and it works just fine. The output is as follows: Polling http://feeds.feedburner.com/CalculatedRisk again to test conditional get support. EVENT: Feed Polled. URL = http://feeds.feedburner.com/CalculatedRisk EVENT: Feed Unchanged. URL = http://feeds.feedburner.com/CalculatedRisk If a "Feed Unchanged" event fired then the server supports conditional gets. The Java example is therefore working fine with the Rome Fetcher 0.9 jar from here. http://wiki.java.net/bin/view/Javawsxml/RomeFetcher I will download the new BSF4REXX update and install it this afternoon. Thanks again. |
|
#6
| |||
| |||
| rony, I ran your code with the new beta and, as expected, received basically the same message. Here is the message: java.lang.IllegalArgumentException: event set 'fetcher' unknown for source type 'class com.sun.syndication.fetcher.impl.HttpURLFeedFetche r' org.apache.bsf.util.ReflectionUtils.addEventListen er(ReflectionUtils.java: 92) org.apache.bsf.util.EngineUtils.addEventListener(E ngineUtils.java: 96) org.rexxla.bsf.engines.rexx.RexxAndJava.javaCallBS F(RexxAndJava.java: 1618) org.apache.bsf.BSFException: BSF4Rexx subfunction "addEventListener": could not add 'eventText', got BSF exception: [[EngineUtils.addEventListener()] ouch while adding event listener: java.lang.IllegalArgumentException: event set 'fetcher' unknown for source type 'class com.sun.syndi org.rexxla.bsf.engines.rexx.RexxAndJava.javaCallBS F(RexxAndJava.java: 1628) |
|
#7
| |||
| |||
| Hi Raetus, regli wrote: > I ran your code with the new beta and, as expected, received basically > the same message. Here is the message: > > java.lang.IllegalArgumentException: event set 'fetcher' unknown for > source type 'class > com.sun.syndication.fetcher.impl.HttpURLFeedFetche r' > > org.apache.bsf.util.ReflectionUtils.addEventListen er(ReflectionUtils.java: > 92) > > org.apache.bsf.util.EngineUtils.addEventListener(E ngineUtils.java: > 96) > org.rexxla.bsf.engines.rexx.RexxAndJava.javaCallBS F(RexxAndJava.java: > 1618) > > org.apache.bsf.BSFException: BSF4Rexx subfunction > "addEventListener": could not add 'eventText', got BSF exception: > [[EngineUtils.addEventListener()] ouch while adding event listener: > java.lang.IllegalArgumentException: event set 'fetcher' unknown for > source type 'class com.sun.syndi > > org.rexxla.bsf.engines.rexx.RexxAndJava.javaCallBS F(RexxAndJava.java: > 1628) just had time to look into this a little bit. The problem seems to be with the Java class "com.sun.syndication.fetcher.impl.AbstractFeedFetc her", which defines the event listener related methods, which the subclass "com.sun.syndication.fetcher.impl.HttpURLFeedFetch er" inherits. Here's the output of running "javap" (from the JDK) against that class: --------- cut here --------- F:\test\bsf4rexx\raetus>javap -public com.sun.syndication.fetcher.impl.AbstractFeedFetch er Compiled from "AbstractFeedFetcher.java" public abstract class com.sun.syndication.fetcher.impl.AbstractFeedFetch er extends java.lang.Object implements com.sun.syndic ation.fetcher.FeedFetcher{ public com.sun.syndication.fetcher.impl.AbstractFeedFetch er(); public synchronized java.lang.String getUserAgent(); public synchronized void setUserAgent(java.lang.String); public void addFetcherEventListener(com.sun.syndication.fetche r.FetcherListener); public void removeFetcherEventListener(com.sun.syndication.fet cher.FetcherListener); public synchronized boolean isUsingDeltaEncoding(); public synchronized void setUsingDeltaEncoding(boolean); public static com.sun.syndication.feed.synd.SyndFeed combineFeeds(com.sun.syndication.feed.synd.SyndFee d, com.sun.syndication.feed.synd.SyndFeed); } --------- cut here --------- From the above signatures the following two methods are meant to be event related methods: public void addFetcherEventListener(com.sun.syndication.fetche r.FetcherListener); public void removeFetcherEventListener(com.sun.syndication.fet cher.FetcherListener); This is the event pattern used throughout Java: given some event type _XYZ_ one needs to implement the event related methods with the following signature public void add_XYZ_Listener (_XYZ_Listener) public void remove_XYZ_Listener (_XYZ_Listener) The problem with the "com.sun.syndication.fetcher.impl.AbstractFeedFetc her": the argument is *not* of type "com.sun.syndication.fetcher.FetcherEventListe ner" as indicated by the typename "FetcherEvent" used in the methods "add...Listener(...Listener)" and "remove...Listener(...Listener)"! [Or, alternatively the {add|remove}FetcherEventListener(...) listener argument object would need to be of type "com.sun.syndication.fetcher.FetcherEventListener" .] As a result the Java Introspector is not able to infer an event set from that class, and therefore no event adapter can be generated on the fly for it! Maybe you could file a bug report with the ROME-fetcher people asking to rename the method as follows (removing the substr "Event" from the method name): "addFetcherEventListener(...)" to "addFetcherListener(...)", and "removeFetcherEventListener(...)" to "removeFetcherListener(...)". Alternatively, you could fix this by correcting these two method names in the source of the ROME-fetcher package, re-compile both classes and experiment thereafter. (If I had a little bit more time I would do it myself, but unfortunataly, these days are *extremely* stressful for me, so it will take some time, before I gain some spare resources again.) HTH, ---rony P.S.: Also, to be really fully adhering to this simple Java event pattern, they should also add a method "get_XYZ_Listeners()" (note the plural 's') which would return an array of "_XYZ_Listener" objects to which events get dispatched to. |
|
#8
| |||
| |||
| rony, Thanks very much for your efforts. I will also have to take my time a little as something unexpected has come up. I will play around with the the Fetcher project which is something I intended to do anyway. Thanks again and I will keep you posted. |
![]() |
| Thread Tools | |
| Display Modes | |
In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.