Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #28054

distributed initialisation code

From Roedy Green <see_website@mindprod.com.invalid>
Newsgroups comp.lang.java.programmer
Subject distributed initialisation code
Date 2014-04-12 21:39 -0700
Organization Canadian Mind Products
Message-ID <hm4kk9ti54lbps7m2o0apm7e61cef7paje@4ax.com> (permalink)

Show all headers | View raw


I wondered what sort of techniques you use for this sort of problem.

Lets say I have a program that processes hundreds of files. Each one
may be processed by some set of hundreds of processing modules that
may be called many times per file, for different parts of it.

In that processing code there is a need for:

one-time startup initialisation = handled by static init.

shut down = handled by Runtime.getRuntime().addShutdownHook

But what about some code that should be run every time a new file is
loaded.

Possible solutions

1. mix code from many different processors together in a newFileInit
method.  All those variables must be public. This is very
unencapsulated.

2. Pass a boolean to every processor on every call  to tell it if this
represents a new file. Most of the time, the boolean is of no
interest.

3. some kind of way of registering a callback that gets called on
reading a new file.  Such a scheme might be easily extendable to
handle various conditions without disturbing existing code. It would
be like addShutdownHook but for more general conditions. Is there a
canned solution?

-- 
Roedy Green Canadian Mind Products http://mindprod.com
"Don't worry about people stealing an idea; if it's original, you'll
 have to shove it down their throats." 
~ Howard Aiken (born: 1900-03-08 died: 1973-03-14 at age: 73)

Back to comp.lang.java.programmer | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

distributed initialisation code Roedy Green <see_website@mindprod.com.invalid> - 2014-04-12 21:39 -0700
  Re: distributed initialisation code Roedy Green <see_website@mindprod.com.invalid> - 2014-04-12 23:12 -0700
  Re: distributed initialisation code Marcel Müller <news.5.maazl@spamgourmet.org> - 2014-04-13 09:29 +0200

csiph-web