SelNthItem component not providing REJ stream

Discussion about JavaFBP issues and problems

SelNthItem component not providing REJ stream

by bobcorrick » November 27th, 2011, 8:43 am

JavaFBP-2.5.jar

I created a diagram that included a SELECT block using SelNthItem, such as:
Code: Select all
  <description>SELECT</description>
  <blockclassname>C:\FlowBasedProgramming\JavaFBP-2.5.jar!com.jpmorrsn.fbp.components.SelNthItem</blockclassname>


On testing, the ACC output went to a ShowText window, but my REJ output to the console was empty:
Code: Select all
C:\FlowBasedProgramming>set CLASSPATH=.;C:\Program Files\Java\jre6\lib\ext\QTJava.zip;.;C:\FlowBasedProgamming\JavaFBP-2.5.jar
C:\FlowBasedProgramming>java bob/SimpleSortContents
Run complete.  Time: 0.328 seconds
C:\FlowBasedProgramming>


I extracted SelNthItem.java from the jar file and was able to make the REJ port send data. Here are the changes (lines with < at the beginning):
Code: Select all
< package bob;
---
> package com.jpmorrsn.fbp.components;

<  *  Bob, November 2011: Make REJ port optional, and update the description.
< */
< @ComponentDescription("Select from IN one packet by NUMBER (0 means first), sending via ACC, rejected packets via REJ")
< @OutPorts( { @OutPort(value = "ACC"), @OutPort(value = "REJ", optional = true) })
---
> */
> @ComponentDescription("Select a specific item from a stream by number")
> @OutPorts( { @OutPort(value = "ACC"), @OutPort(value = "REJ") })

<           rejport.send(p);
<           //drop(p); // undo "fudge to save space"
---
>           //rejport.send(p);
>           drop(p); // fudge to save space


Using this component instead seemed to work: I had correct output in a window and on the console.

HTH
Bob
bobcorrick
 
Posts: 55
Joined: November 22nd, 2011, 9:36 pm

Re: SelNthItem component not providing REJ stream

by jpaulm » November 27th, 2011, 5:59 pm

Sorry about that! I guess I was testing premature closedown of components - it never occurred to me this component might be used for real work :-)

I will change the function as you suggest and add it back into the jar file and SourceForge. Actually I think the cleanest would be to write:

Code: Select all
while ((p = inport.receive()) != null) {
      if (i == ct) {
        accport.send(p);
      } else {
        if (rejport.isConnected())
          rejport.send(p);
        else
          drop(p);
      }
      i++;
    }



And I will pick up your ComponentDescription (I didn't see it at first).

Keep the feedback coming!
jpaulm
Site Admin
 
Posts: 31
Joined: March 31st, 2011, 12:58 am

Re: SelNthItem component not providing REJ stream

by jpaulm » November 27th, 2011, 7:27 pm

For your information/amusement, I have remembered why SelNthItem had that rather odd logic: I had a humongous email file, and had a retrieve a particular email from it. After retrieving the desired item, I wanted the whole network to come down gracefully, without having to process the entire rest of the file! In hindsight, the component could have been given a different, less general name, such as "Bring down network gracefully soon after retrieving n'th item". Or the terminate function could have been moved into a separate component, perhaps even triggered by the retrieved item - there are several ways of achieving this.

Thanks again for stumbling over this one 8-)
jpaulm
Site Admin
 
Posts: 31
Joined: March 31st, 2011, 12:58 am

Re: SelNthItem component not providing REJ stream

by bobcorrick » December 1st, 2011, 3:57 pm

I have applied the suggested change in my custom copy of your SelNthItem component and it seems to work fine in a simple network.

On substituting it into a more complex network, I discovered a deadlock that I hope to diagnose once I have read some more! (I assume the problem is in my network - it includes a custom Duplicate component that I think was a bad idea.)

PS I renamed "my" SelNthItem to SelectOneItem, which I think is easier on the eye :)
Bob
bobcorrick
 
Posts: 55
Joined: November 22nd, 2011, 9:36 pm

Re: SelNthItem component not providing REJ stream

by jpaulm » December 1st, 2011, 5:55 pm

Looking forward to hearing the cause... Sometimes you can just eyeball the network...
jpaulm
Site Admin
 
Posts: 31
Joined: March 31st, 2011, 12:58 am


Return to JavaFBP



Who is online

Users browsing this forum: No registered users and 0 guests

cron