Here is a FBP solution for CSV Viewer "iteration 0".
This is like Iteration I but without being interactive or presenting borders around the fields. It just pads the CSV fields to the maximum length (it is similar to converting from CSV to fixed length format).Here is my diagram for Iterations 1 and 2 - they seem to be
approximately the same (in my view, the requirement for the 'L' option
in Iteration 1 basically forces the same design as Iteration 2).
Iteration 3 will be a shade more complex, but I believe it is a sort of
superset, so it will actually work for 1 and 2.
I believe I can just attach my picture - here goes...
1. I am planning to use a HashMap for Iterations 1 and 2, and a database for Iteration 3.
2. Since the pages are fixed size, you're right - I can store them in CSV form and format them at display time. It's a trade-off. Same component - I can just move it to the display part of the network!
3. The latter - it just flows in a circle.
4. Initially packets containing one string - for each line; later the lines will get aggregated into pages.
The first part of the code I have worked on is the Java Swing display component. as that was the part I was most unsure about. That's working, so I feel the rest should be plain sailing. (I hope)
Of course, as the code evolves, I will change the diagram.
Thanks for your feedback.
Paul
Sent from Samsung Galaxy Tab (tm) on Rogers
> However, loops in FBP (network loop topologies, not loops inside
> components) have a unique problem that arises when you want to close
> them down. The problem is that the close-down rule for processes is
> that a process only closes down when all of its upstream processes
> have closed down.
When a process closes down, the library should catch the ThreadDeath
exception and close all the ports associated with the process. This would
give more reliable semantics, though it will not break deadlocks as such.
(Note that after ThreadDeath is caught, it must be propagated to allow
Java to shut down the thread.)
--
There are three kinds of people in the world: John Cowan
those who can count, co...@ccil.org
and those who can't.
Regards,
Paul
On 25/01/2012 3:56 PM, John Cowan wrote:
> Paul Morrison scripsit:
>
>> However, loops in FBP (network loop topologies, not loops inside
>> components) have a unique problem that arises when you want to close
>> them down. The problem is that the close-down rule for processes is
>> that a process only closes down when all of its upstream processes
>> have closed down.
> When a process closes down, the library should catch the ThreadDeath
> exception and close all the ports associated with the process. This would
> give more reliable semantics, though it will not break deadlocks as such.
>
> (Note that after ThreadDeath is caught, it must be propagated to allow
> Java to shut down the thread.)
>
> BTW is there a generic way in Java to have different (unexpected)
> Exceptions (and/or Errors) throw ThreadDeath? Would you be willing to
> sign on as a JavaFBP developer on SourceForge? :-)
Catch Throwable and have it generate a ThreadDeath encapsulating the Throwable
and then throw it. Two caveats: you must catch Throwable as the last catch
in the try-catch statement, and you must make sure to do the same cleanup
for Throwable that you do for ThreadDeath, because the ThreadDeath will not be
caught again.
So here's the general skeleton:
try {
[code to execute the process]
} catch (ThreadDeath e) {
closeAllPorts();
} catch (Throwable e) {
closeAllPorts();
throw new ThreadDeath(e);
}
--
John Cowan co...@ccil.org http://ccil.org/~cowan
Nobody expects the RESTifarian Inquisition! Our chief weapon is
surprise ... surprise and tedium ... tedium and surprise ....
Our two weapons are tedium and surprise ... and ruthless disregard
for unpleasant facts.... Our three weapons are tedium, surprise, and
ruthless disregard ... and an almost fanatical devotion to Roy Fielding....
Paul
On 25/01/2012 6:12 PM, John Cowan wrote:
> Paul Morrison scripsit:
>
>> BTW is there a generic way in Java to have different (unexpected)
>> Exceptions (and/or Errors) throw ThreadDeath? Would you be willing to
>> sign on as a JavaFBP developer on SourceForge? :-)
> Catch Throwable and have it generate a ThreadDeath encapsulating the Throwable
> and then throw it. Two caveats: you must catch Throwable as the last catch
> in the try-catch statement, and you must make sure to do the same cleanup
> for Throwable that you do for ThreadDeath, because the ThreadDeath will not be
> caught again.
>
> So here's the general skeleton:
>
> try {
> [code to execute the process]
> } catch (ThreadDeath e) {
> closeAllPorts();
> } catch (Throwable e) {
> closeAllPorts();
> throw new ThreadDeath(e);
> }
>
> Java doesn't like it - on "throw new ThreadDeath(e)" it says
> "Unhandled exception type" . Have you tried it recently? If so, can
> you send me a sample of the code (I may have dropped a semi-colon)...
Hmm. Apparently there is only a zero-argument constructor for ThreadDeath.
Try using "throw new ThreadDeath()" instead.
No, I didn't test it.
--
John Cowan <co...@ccil.org> http://www.ccil.org/~cowan
One time I called in to the central system and started working on a big
thick 'sed' and 'awk' heavy duty data bashing script. One of the geologists
came by, looked over my shoulder and said 'Oh, that happens to me too.
Try hanging up and phoning in again.' --Beverly Erlebacher
I confess I am out of my depth here...
BTW are there other pronouncements of the sage Kehlog Ahlbran?
> Nope, didn't work either... Actually, the first line - catch
> (ThreadDeath e) - gave the message Unreachable catch block - but I
> could force a throw somewhere in the code...
That sounds like there is a more inclusive catch clause preceding it.
The ThreadDeath catch should come first, then the Throwable.
Are there any other catch blocks in the try statement?
> BTW are there other pronouncements of the sage Kehlog Ahlbran?
Oh yes, a whole book called _The Profit_.
Online at http://rsidd.online.fr/profit/ .
> --
> http://jpaulmorrison.blogspot.com/
--
After fixing the Y2K bug in an application: John Cowan
WELCOME TO <censored> co...@ccil.org
DATE: MONDAK, JANUARK 1, 1900 http://www.ccil.org/~cowan
P.
> And that�s why I�d like to align the message of Flow-Based
> Programming with the message of Flow-Design/Event-Based Components
> (FD/EBC). Currently they are two approaches because FBP is rooted
> in parallel programming. You libs are all about running processes on
> multiple threads.
FBP isn't actually parallel, it's concurrent. It does not matter
whether the processes execute in separate threads, separate OS
processes, separate cores, or separate machines connected over the
Internet. There may be any amount of parallelism or none in the
implementation. Parallelism is a speed hack; concurrency is a way of
life.
Indeed, Hoare's CSP model ("communicating sequential processes") is
equivalent to FBP, except that FBP processes do not have explicit
knowledge of their neighbors in normal cases.
> But FD/EBC come from the world of sync programming - but allowing the
> developer to move into the real of parallel processing.
A Sufficiently Smart Compiler could take an FBP program and squeeze out
unnecessary concurrency to run it on as few threads as possible. It's
a hard problem, and threads are normally efficient enough, but it's
possible in principle.
--
Values of beeta will give rise to dom! John Cowan
(5th/6th edition 'mv' said this if you tried http://www.ccil.org/~cowan
to rename '.' or '..' entries; see co...@ccil.org
http://cm.bell-labs.com/cm/cs/who/dmr/odd.html)
> That there may be any amount of parallelism in a FBP network... I did
> not read that from Paul�s book. Sorry.
I didn't mean "any amount" literally, only at the level of components.
Each component executes serially. In addition, some components
("sponges") may defeat parallelims by buffering their entire input before
producing any output. A sort component is a good example of this.
--
John Cowan co...@ccil.org http://ccil.org/~cowan
There was an old man Said with a laugh, "I
From Peru, whose lim'ricks all Cut them in half, the pay is
Look'd like haiku. He Much better for two."
--Emmet O'Brien
> Interesting distinction! I confess I have tended to use these terms
> interchangeably - thereby no doubt adding to the confusion! Care to
> expand on this, John?
Parallelism refers to physically simultaneous execution. When you raise
both arms above your head, you do so in parallel. Nothing can be more
parallel than the number of execution agents simultaneously available:
on an 8-core system, you can add up 8 rows of a matrix in parallel,
but not 16 rows. Furthermore (as I just posted) some problems cannot
be parallelized, whereas others can be executed entirely in parallel.
Concurrency refers to conceptually simultaneous execution. When you
juggle balls, you are executing a concurrent program: despite appearances,
jugglers only throw or catch one ball at a time. A concurrent program
can execute on a single execution agent, on as many agents as it has
concurrent components, or anything in between, so concurrency does not
depend on parallelism. We usually speak of concurrency when there is
interaction between the concurrent components.
Flow-based programming is based on the concurrent execution of mostly
isolated processes that communicate via flows. Because the components
are isolated, they may be executed in parallel or not. Because there
are no constraints on what components may do with their inputs, parallel
execution may or may not actually speed up the computation.
--
And through this revolting graveyard of the universe the muffled, maddening
beating of drums, and thin, monotonous whine of blasphemous flutes from
inconceivable, unlighted chambers beyond Time; the detestable pounding
and piping whereunto dance slowly, awkwardly, and absurdly the gigantic
tenebrous ultimate gods --the blind, voiceless, mindless gargoyles whose soul
is Nyarlathotep. (Lovecraft) John Cowan co...@ccil.org
> But FD can scale up to concurrent and distributed programming. It
> shares data flows with FBP. But it favors a more explicit switch to
> concurrency by marking certain functional units as "running on their
> own" (i.e. being executed on one or more separate threads). Also FD
> does not require concurrent functional units to "own" their threads.
FBP does not require it either; it's just the simplest implementation.
If it's efficient enough, then fine. If it's not, you may have to do
something quite complex to figure out which components can share threads.
Do you know about the Faust programming language? It too is synchronous
data flow, and it compiles down to C++.
> PS: I like your quote by Lovecraft. Reminded me of some 30 years ago
> when I read all his books. [sigh] Is the quote from "The Dream-Quest
> of Unknown Kadath"?
Lovecraft actually uses the sentence in two different stories:
"Nyarlathotep" and "The Dream-Quest of Unknown Kadath." The wording is
slightly different, however. I don't remember offhand which one this is.
--
But you, Wormtongue, you have done what you could for your true master. Some
reward you have earned at least. Yet Saruman is apt to overlook his bargains.
I should advise you to go quickly and remind him, lest he forget your faithful
service. --Gandalf John Cowan <co...@ccil.org>
Didn't realize you wrote the AppKata spec - it's a pretty neat idea!
Thanks for doing this! However... as a user I think I would want to at
least be told if my request could not be satisfied *at this time*! So,
even if we don't hang the app, we could have a message like "Working on
it - come back later". From there, it's a small step to giving the user
a choice. So... here is my diagram - all you have to do is remove the
blocks marked with 2 asterisks if you don't want to give the user a choice.
The idea of annotating the diagram with data descriptions is a very
attractive one, and one that I've wrestled with over the years -
although I should point out that in CSV Viewer Iteration 3, you have two
processes accessing a shared database asynchronously, which is not
really a "flow".
However, I take your general point - the problem in my view is the wide
variety of data types flowing between processes. I would love to be
able to check compatibility between what one process emits and what the
next one accepts - at design time, ideally. I did try in DrawFBP to use
the isAssignableFrom() method, but this only works with a Java
description of data types, and anyway it's not general enough.
If you look at Fig 10.3 in my book -
http://www.jpaulmorrison.com/fbp/simpapp3.shtml (same Fig number in the
new edition), you will see a diagram of the data stream coming out of
Collate. The column headed IPs are basically class instances, so the
overall stream is a nested structure of class instances. As I say later
in the book, you could in fact use a form of regular expression notation
to describe this structure (see chapters 24 and 25 in the online version
- 23 and 24 in the new edition).
You also have some components that have no constraints on the classes
they accept or the classes they generate, e.g. the JavaFBP component
Concatenate, which takes all the IPs coming into element 0 of input port
array IN, followed by those coming into element 1, and so on, up to
whatever size the array port is defined as. So, if I want to put
Concatenate between a process emitting A's and a process accepting A's,
but Concatenate can accept and emit anything, how do I express this?
So, while I am very open to suggestions about formal encoding of data
stream properties, I see no reason to hold my breath waiting for one to
come along! We built a whole banking system (at least the batch part)
without ever having, or needing, a formal notation...
Regards,
Paul
> However, I take your general point - the problem in my view is the
> wide variety of data types flowing between processes. I would love to
> be able to check compatibility between what one process emits and what
> the next one accepts - at design time, ideally. I did try in DrawFBP
> to use the isAssignableFrom() method, but this only works with a Java
> description of data types, and anyway it's not general enough.
What really needs to be done (and unfortunately I don't have time/energy
to tackle it) is to update JavaFBP and C# FBP to use parameterized
classes. Thus instead of just having Packets which hold Objects, you
define Packet<Foo>, which is a Packet that holds Foos. The compiler
will check that only a Foo is put into a Packet and only a Foo emerges
from it. Various other classes would need to be parameterized as well.
Once that's done, it's possible to modify DrawFBP to allow each
component to be annotated with a type name, and then generate the
appropriate kinds of Ports.
--
John Cowan co...@ccil.org http://www.ccil.org/~cowan
Most people are much more ignorant about language than they are about
[other subjects], but they reckon that because they can talk and read and
write, their opinions about talking and reading and writing are as well
informed as anybody's. And since I have DNA, I'm entitled to carry on at
length about genetics without bothering to learn anything about it. Not.
--Mark Liberman
Paul
> For this you would use Generics in Java -
> https://www.google.com/search?q=generics+in+java
For some reason I forgot the word "generic" until I'd already posted.
But that's what I'm talking about.
> This is available in Java from version 1.5 on. From my understanding,
> and John Cowan's comments, this is not a trivial change for the
> FBP system.
No, it's not, but it's long overdue. Generics have been in Java for eight
years now, and I'd say they are a well-accepted part of a programmer's
toolkit, supported by all current versions of Java (6 and 7).
--
Well, I have news for our current leaders John Cowan
and the leaders of tomorrow: the Bill of co...@ccil.org
Rights is not a frivolous luxury, in force http://www.ccil.org/~cowan
only during times of peace and prosperity.
We don't just push it to the side when the going gets tough. --Molly Ivins
Sent from Samsung Galaxy Tab (tm) on Rogers
I used Hashmap in the other App Kata as it is more widely available eg early Android versions. But that is unfinished, as I have been concentrating on non-technical matters outside work (eg being a school governor).
One thing that concerned me is that the keys in the map were very tied to the fact that I was reading a file, and I wanted to make an alternative that read from a database. Then I should be able to separate these aspects better.
At work I found time to work through some Codecademy examples of JavaScript, now that it is available server side as well as on browsers. No time to actually get into node.js though :-( maybe once I finish some Java fbp I will try the js path.
All the best,
Bob
-----Original Message-----
From: Paul Morrison
Sent: 29 Mar 2012 01:31:11 GMT
To: flow-based-...@googlegroups.com
Subject: Re: AppKatas using FBP