perl accept()

I think a common Perl socket idiom (used repeated in my scripts) is


while ( accept(Client,Server) ) {
# use Server and Client file handles
close Client;
}
close Server;

I think the while loop would run only once (P 442 [[ programming perl ]]). The first time it runs, accept() blocks until a client connects. After the connect, the loop runs for n seconds, the duration of the connection. At end of the connection, this script closes Client, exits the loop (?), and closes Server stream.

How does the server continue to service other clients? I think fork and exec is the standard solution, spawning a new process. In contrast, Java spawns a new thread — perhaps more efficient.

Remember a single-thread NIO server can handle thousands of sockets, one for each concurrent client. Even a traditional IO server can spawn hundreds of threads.

Hundreds of “processes” sounds like too heavy for an ordinary OS. Apache httpd in our servers typicall spawn dozens of child processes.

Advertisements

finally execution is "guaranteed"@@ UNLESS

[24 May] guaranteed by JVM.

q: unless system powers off before it can?
A: agree. since the guarantee is given by jvm.

a7: finally still runs. Perhaps finally can do a return and /disarm/ the bomb?

q: unless the fatal error leads to an immediate jvm crash?
A: I don’t think so. If JVM can manage the fatal error, it can run finally{}.

q: what if there’s an endless loop in the try or catch?
A: then finally{} is expected to be delayed. JVM will honor the class owner’s expectations.

a690: right before the search for a /matching catch/ in the stack? see other blog posts on try/catch/finally execution order

q7: when does my finally run if my catch says exit()

q690: when does my finally run in the presence of my catches and also catches up on the call stack?

cross currency trades and cross rate derivation

There’s confusion over the term “cross”. I believe it means the pair is not “native” to the broker/dealer you are using, so they have to synthesize 2 “native” trades. If your broker/dealer offers only USD/XXX , then a lot of non-USD currency pairs will be crosses.

If you are a big dealer bank using EBS and Reuters, then you can combine those 2 brokers’ offerings together and present a consolidated list of “native” pairs. Anything not in the list is considered a cross currency pair. Note EBS/Reuters “native” spreads are very tight. This is a defining feature of “native” pairs.

Since a cross is always synthesized using 2 pairs, transaction cost and bid/ask spread is higher.
——————-
In the context of “cross rate”, this term means “an exchange rate between 2 non-USD currencies”. That’s a USD cross. There are also Euro crosses — any non-Eur currency pair whose rate is computed from 2 Eur rates.

If USD/AAA has a bid/offer and USD/BBB has a bid/offer, and CCC/USD has a bid/offer. When computing the cross rates between A B and C, just remember to always take the worse prices, which are the safest prices for the market-maker.
– Offer of the cross pair is worse joining worse
– Bid of the cross pair is worse joining worse too

One principal, but many scenarios. Here’s one scenario.Given
1) USD/CHF = 0.9648/52
2) USD/JPY = 82.64/69
CHF/JPY offer must be computed as USDJPY / USDCHF, but which number by which number? Worst offer quote is the highest, so 82.69 / 0.9648 = 85.71.

Here’s the math explained in English. As a market maker who is publishing the 4 quotes of 1) and 2), at what price am i willing to convert my CHF into JPY? Well, I would convert to USD then JPY, using the safest/greediest conversion rates among my outgoing quotes. I would safely convert from CHF to USD at 0.9648, then safely convert from USD to JPY at 82.69.

2min intro to NULL (sql)

http://www.oracle.com/technology/oramag/oracle/05-jul/o45sql.html is a more complete list of jolts. But for now …

#1 jolt: “the NOT-trap” for any cond3 such as “amount > 10” or “id=order.customer_id” … ,
if
select … where cond3 –> 30% of the rows,
then
select … where NOT cond3 –> ?


#2 jolt: “ignore”

where col3 = …
where col3 > …
where col3 LIKE …
where col3 IN …

These filters will ignore NULL entries. Yes, ignore their existence. Reason? null means “unknown” so such an entry is perhaps IN and perhaps not IN.

context-scope = application-scope

I have seen authors using the twin terms “context-scope” and “application-scope” interchangeably.

This is the first thing to bear in mind. After that, recognize that

* context-scope is related to ServletContext, a name used repeatedly in some files
* application-scope is related to web-app, a name used in some files too.

Lastly, remember that we are talking about ATTRIBUTES when we mention these scopes ie

context-scope attributes = application-scope attributes

P309 [[ head first servlet ]]

identical hashCode in HashSet

A HashSet containing 2 twin objects with identical hashCode()?

I think they will co-exist in the HashSet. hashCode() never promises “unique” hashcode, but HashSet promises that 2 “different” objects would be accepted as 2.

Now “different” and “same” are defined by … equals() method , which should be overriden in the key classes used as HashSet keys.

php packages4people build`a simple site

Mambo, moodle, phpnuke, drupal are some of the well-known php “content management” packages. I once used mambo and moodle. Exellent quality and usability.

These open-source packages can help a lay person put together a website quickly. Compared to a from-scratch approach, a package offers, among other things,
* nicer web pages
* perhaps faster development, if the package supports your requirement
* fewer bugs, better tested

There are drawbacks.

* Your custom database logic may be harder to implement.

* I feel you would have a hard time understanding the source code — dozens of source files, containing thousands and thousands of lines — before you can “hack” the code.
* you may realize you only need 1% of the source code to implement your requirement. It would have been far more manageable if you could throw away the other 99%. Not easy.

If you have time to search, see if you can find some bare-bones php “content management” mini-packages. If you find one, let me know.