
Ahhhh! A warm hug from my Ruby code.
This is not, unfortunately, a blog dedicated to that great twelve volume series of novels by Anthony Powell. However, it is a form of record of my journey through the world of information technology; a journey motivated by both profit (it is intimately related to my profession) and inquisitiveness (I love to know how things work). It is my intention, therefore to record. These records are primarily for my benefit, but may be useful to others as a side effect.
Start Logging:
Stop Logging:
Note: These scripts were a bit of a nigthmare to write because of the almost complete lack of documentation of the TivoliPerfEngine MBean. However some checking of the xml config files which WAS uses, some cross referencing with the manual UI version of the same steps, and a good dose of trial and error finally bore fruit. I should thank two of my collegues (you know who you are) who helped me with some pointers when I got stuck.
# NOTE: Edit the following two variables for your environmentTo run it just save it as a file called set_trace_levels.jacl and run with the command:
# They can be discerned from the path to your instance's bin directory
# The following shows the deployment manager ("dmgr") in the "myCell" node
set node myCell
set server dmgr
# Get up the variables required by the rest of the script
set svr [$AdminConfig getid /Node:$node/Server:$server/]
set ts [$AdminConfig list TraceService $svr]
# Modify the trace settings
# NOTE: Edit this settings string to reflect the settings you require
$AdminConfig modify $ts {{startupTraceSpecification *=warning=enabled:SystemErr=all=enabled}}
# Make the changes permanent
$AdminConfig save
./wsadmin.sh -port [SOAP port] -user [myWASAdminUID] -password [myPassword] -f set_trace_levels.jaclNOTE: If you're on Windows, change "wsadmin.sh" to "wsadmin.bat"
{int x => x+1}Primary:
{int x, int y => x+y}
{String x => Integer.parseInt(x)}
{=> System.out.println(“hello”);}
{int => int}Type:
{int, int => int}
{String => int throws NumberFormatException}
{ => void}
{T => U}
package java.lang.function;
public interface IO {
int invoke(A a0) throws X;
}
withLock(lock, {=>
doSomething();
});
withLock(lock) {ControlStatement:
doSomething();
}
void incrementBalance(int deposit) {(b) Using a proposed new closure-based API:
myLock.lock();
try {
balance += deposit;
} finally {
myLock.unlock();
}
}
void incrementBalance(int deposit) {(c) Using the control statement syntax:
Locks.withLock(myLock,
{ => balance += deposit; });
}
void incrementBalance(int deposit) {2. Aggregate Operations - Make a new list by applying a function to each element of an existing list:
Locks.withLock(myLock) {
balance += deposit;
}
}
List3. Interaction with existing APIs - launch a task using an executorparseInts(List strings)
throws NumberFormatException {
return Collections.map(
strings, {String s => Integer.decode(s)});
}
void launch(Executor ex) {(b) Useing a closure:
ex.execute(new Runnable() {
public void run() {
doSomething();
}
});
}
void launch(Executor ex) {(c) Using the control statement syntax:
ex.execute({ =>
doSomething();
});
}
void launch(Executor ex) {3. Interaction with existing APIs - Add a Swing listener
ex.execute() {
doSomething();
}
}
void addListener(final ItemSelectable is) {(b) Using a closure:
is.addItemListener(
new ItemListener() {
public void itemStateChanged(ItemEvent e)
{ doSomething(e, is); }
}
);
}
void addListener(final ItemSelectable is) {(c) Using the control statement syntax:
is.addItemListener(
{ ItemEvent e => doSomething(e, is); }
);
}
void addListener(final ItemSelectable is) {New APIs
is.addItemListener(ItemEvent e :) {
doSomething(e, is);
}
}
Listlist = …;
Integer sum = Collections.reduce(
list,
{Integer x, Integer y => x+y});
musicdb.getRecordings("my_artist")REST
GET /music/artist/my_artist/recordingsCaching
@ProduceMime("application/xml")URI Templates
protected void doGet(HttpServletREquest request,
HttpServletResponse response)
@URITemplate("/artists/{id}") public class Artist extends HttpServlet { ...This means your container should only call this servlet when requests match this template. To take this one step farther we can combine and apply these annotations to a POJO:
@URITemplate("/artists/{id}")Declaring Resource Class Methods
@ProduceMime("application/xml") public class Artist { @HttpMethod // Needed as we no longer implement HttpServlet InputStream getXml(@URIParam("id") String artist) { ... } @ProduceMime("application/json") @HttpMethod // Needed as we no longer implement HttpServlet InputStream getJson(@URIParam("id") String artist) { ... } @HttpMethod @UriTemplate("recordings") InputStream getRecordingsXml(@UriParam("id") String artist) { ... }
}
@HttpMethod public XXX getXXX( ) { ... } @HttpMethod("GET") public XXX find( ) { ... }Method Return Types HttpResponse - provide specialised subclasses for common types of response such as Redirect, Resource Creation, etc.
@HttpMethodMethod Parameters
public Recording getRecording( )
@HttpMethodDeployment Options
public Recording updateRecording(
@URIParam("id") String id, Recording updatedRecording)
7.class => FixnumThere is also sweet syntactic sugar for literals:
File.open(filename) { | file | line = file.gets }In this example the file is autoamtically closed. You need not worry about this as a programmer.
myappYou put your code in the controllers and views. There is no need to wire everything up unlike in Struts or JSF.
app
controller - the "C" of MVC
helpers - DRY extracted code from the other app elements
model - the "M" of MVC
views - the "V" of MVC
config - config files
db - db config and migrations files
lib - libraries
public - static html content
test - unit tests
# rails myapp - Creates a rails app with the above structure called "myapp"Components
# ruby script/generate - Generates the MVC, migrations and scaffolding etc for your rails app