|
|
Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs
I recently switched to Mac OS X from Windows and I'm thrilled with the results. But then again, I only spent a short five-year stint on Windows NT and XP; before that I was strictly a Unix developer for 15 years, mostly on Sun Microsystems machines. I also was lucky enough to develop software under Nextstep, the lush Unix-based predecessor to Mac OS X, so I'm a little biased.
Aside from its beautiful Aqua user interface, Mac OS X is Unix, arguably the best operating system in existence. Unix has
many cool features; one of the most well known is the pipe, which lets you create combinations of commands by piping one command's output to another's input. For example, suppose you
want to list source files from the Struts source distribution that invoke or define a method named execute(). Here's one way to do that with a pipe:
grep "execute(" `find $STRUTS_SRC_DIR -name "*.java"` | awk -F: '{print }'
The grep command searches files for regular expressions; here, I use it to find occurrences of the string execute( in files unearthed by the find command. grep's output is piped into awk, which prints the first token—delimited by a colon—in each line of grep's output (a vertical bar signifies a pipe). That token is a filename, so I end up with a list of filenames that contain the
string execute(.
Now that I have a list of filenames, I can use another pipe to sort the list:
grep "execute(" `find $STRUTS_SRC_DIR -name "*.java"` | awk -F: '{print }' | sort
This time, I've piped the list of filenames to sort. What if you want to know how many files contain the string execute(? It's easy with another pipe:
grep "execute(" `find $STRUTS_SRC_DIR -name "*.java"` | awk -F: '{print }' | sort -u | wc -l
The wc command counts words, lines, and bytes. In this case, I specified the -l option to count lines, one line for each file. I also added a -u option to sort to ensure uniqueness for each filename (the -u option filters out duplicates).
Pipes are powerful because they let you dynamically compose a chain of operations. Software systems often employ the equivalent of pipes (e.g., email filters or a set of filters for a servlet). At the heart of pipes and filters lies a design pattern: Chain of Responsibility (CoR).
Note: You can download this article's source code from Resources.
The Chain of Responsibility pattern uses a chain of objects to handle a request, which is typically an event. Objects in the chain forward the request along the chain until one of the objects handles the event. Processing stops after an event is handled.
Figure 1 illustrates how the CoR pattern processes requests.

Figure 1. The Chain of Responsibility pattern
In Design Patterns, the authors describe the Chain of Responsibility pattern like this:
Avoid coupling the sender of a request to its receiver by giving more than one object a chance to handle the request. Chain the receiving objects and pass the request along the chain until an object handles it.
The Chain of Responsibility pattern is applicable if:
Archived Discussions (Read only)