Showing posts from January, 2009

Initialize Timestamp with nanos

final Timestamp timestamp = new Timestamp(System.currentTimeMillis());
timestamp.setNanos((int)(System.nanoTime() % 1000000000));

Get hostname

private static final Log LOG = Logging.getLog(NodeHelper.class);

* @return a node Id for this instance
public static final String getNodeId () {
final String nodeId = String.format("hostname=%s", getHostname());
return nodeId;

* @return a hostname for this instance
public static final String getHostname () {
String hostname = "error-unknown";
try {
hostname = InetAddress.getLocalHost().getHostName();
} catch (final UnknownHostException e) {
LOG.error(String.format("Error acquiring hostname"), e);
} catch (final RuntimeException e) {
LOG.error(String.format("Error acquiring hostname"), e);
return hostname;

SVN command-line

Slik SVN

Basic SVN Commands

--m "message text"
--username <username>

svn help
svn help <command>
svn help co

svn co svn://[@rev]... [path] --username <username>

#check-in / commit - defaults to user who checked-out
svn ci [path...] -m "message text"

svn propset <propname> <propval> <file path...>
svn propset svn:mime-type text/plain <file path>
svn propset svn:eol-style native <file path>

svn add <dir/file path...>

#Copy - Branch/Tag
WC=Working Copy
WC path -> WC path (copy and sched for addition w/history)
WC path -> URL (immediately commit copy of WC to URL)
URL -> WC path (co and sched for addition)
URL -> URL (branch / tag)
svn cp [src path] [dst path] -m "message"

svn mv <src> <dest>

svn delete <remote url... or local path...>

svn up [path...]
svn up -r <revision>



Telecommuting onto VPN and Windows

kvpnc connects to cisco VPN servers
had to config to not replace default route
Added route intf tun0
After connecting have to update resolv.conf adding local dns, default domain, and search domains

rdesktop and krdc connects to Windows XP
Pidgin with SIP plugin can connect to Microsoft OCS/LCS

Had to install vpnc

Issues resolvconf with Ubuntu later than 8.04


Java EE 5 Tutorial

JBoss 4 JMS configuration

JBoss 4 guide

JBoss configuration

JMS generic message ordering with property and filter Would need to use durable subscriptions for recovery upon failure or restart.

JNDI name ConnectionFactory


InitialContext iniCtx = new InitialContext();
Object tmp = iniCtx.lookup("ConnectionFactory");
QueueConnectionFactory qcf = (QueueConnectionFactory) tmp;
conn = qcf.createQueueConnection();
que = (Queue) iniCtx.lookup("queue/testQueue");
session = conn.createQueueSession(false,


private static ConnectionFactory connectionFactory;

Connection connection = connectionFactory.createConnection();
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Session session = connection.createSession(true, 0); //transacted

MessageProducer producer = session.createProducer(dest);
MessageProducer producer = session.createProducer(queue);

Cisco vpnclient password decoder

volatile array elements are not volatile

There is no way in Java for an arrays elements to be volatile.

Tried using the concurrent AtomicReferenceArray for a matrix (array-of-arrays), but wasn't impressed with the resulting implementation.

private volatile
AtomicReferenceArray<AtomicReferenceArray<Foo>> foos;
foos = new AtomicReferenceArray<AtomicReferenceArray<Foo>>(xSize);
for (int x = 0; x < foos.length(); x++) {
foos.set(x, new AtomicReferenceArray<Foo>(ySize));
Foo foo = foos.get(x).get(y);
foos.get(x).set(y, foo);

A customized thread-safe encapsulation of the data matrix with indexing accessors and mutators is a cleaner implementation.


* Manages an indent for multi-line messages.
* @author Troy T. Collinsworth
public class StringFormattingIndent
private final StringBuilder indent = new StringBuilder();
private final String indentString;

* Uses the default indent - tab.
public StringFormattingIndent ()
this.indentString = "\t";

* Uses a custom indent string.
* @param indentString
public StringFormattingIndent (final String indentString)
this.indentString = indentString;

public void increment ()

public void decrement ()
indent.setLength(indent.length() - indentString.length());

public String getCurrentIndent ()
return indent.toString();

Ubuntu sharing from Windows

Have to load smbfs and samba

Following link describes smbfs mounting

Ant - increasing heap for ant

Add environment variable:

export ANT_OPTS=-Xmx256m

HTTP post of XML - Maven, Jetty, Jersey

Linux-RT processor affinity cpusets

It is very easy to assign tasks to a particular processor or processor set!!!

For proper permissions: sudo or su root or add yourself to the admin group or /etc/sudoers file.
Use /bin/echo or just echo worked on my Ubuntu instance.
Obviously you can omit the full paths and use relative paths below, commands are listed with full paths for clarity.

mount the cpuset filesystem, add it to /etc/fstab to make it permanent and create a script called at startup to perform the subsequent initialization
mkdir /dev/cpuset mount -t cpuset cpuset /dev/cpuset
set the sched_load_balance flag to zero - at that point the scheduler is not moving tasks among processors anymore, you may immediate notice in the System Monitor variation in the processor load if they weren't balanced at the moment this command was executed
cd /dev/cpuset echo 0 > sched_load_balance
create a sub cpuset for each processor or set of processor if you have more than 2
mkdir /dev/cpuset/cpu0 mkdir /dev/cpuset/cpu1

Sybase system queries

Sybase JDBC showplan

in dbvisualizer
set showplan on;
set noexec on;

name, fullname, totio, totcpu, lastlogindate
from master..syslogins
where totio > 0
order by totio

hashkey, sequence,
elap_min, elap_max, elap_avg,
cnt, abort_cnt, qtext
from sysquerymetrics


FROM master..sysprocesses
WHERE time_blocked > 0
ORDER BY time_blocked DESC

//need select on monlocks AND mon_role
select count(*) from master..monlocks

//who is holding locks
SELECT H.spid 'Holding ID',
H.fid 'Holding FID',
SUSER_NAME(H.suid) 'Holding User',
W.spid 'Waiting ID',
W.fid 'Waiting FID',
SUSER_NAME(W.suid) 'Waiting User',
H.status 'Status', 'Lock Type',
W.time_blocked 'Time Blocked',
DB_NAME(L.dbid) 'Database',
OBJECT_NAME(, L.dbid) 'Object Name', 'Lock Page',
L.class 'Lock Class',
H.hostname 'Holding Host',
W.hostname 'Waiting Host',

FireFox hacks

FireFox hack to allow resizing locked popups

Secret settings: type about:config in address bar

JConsole custom MBean GUI tabs

For composite types, favor the newer MXBeans over MBeans

Applying MXBean mapping to your own types

Create UI in custom JPanel constructor, not in:

public SwingWorker newSwingWorker() {

JConsole calls the custom plug-in method passing in a connection:

MBeanServerConnection conn = null;
public void setMBeanServerConnection(
final MBeanServerConnection mBeanServerConnection) {
conn = mBeanServerConnection;
//save connection and automatically
//register for notifications here

To get a proxy to an MBean:

ObjectName oname =
new ObjectName(

SomeMBean b =

Access MBean attributes directly from proxy or as follows:

Object a = conn.getAttribute(oname, "SomeAttributeName");

Invoke MBean methods directly from proxy or as follows:

String[] paramClasses = new St…

Object comparison - handling the null case


return (s1 == s2)
(s1 == null && s2 != null)

Multi-value arrays of arrays (matrices)

As an alternative to multi-valued arrays of arrays in Java, a Map or single array of arrays of custom objects can be utilized to get the same behavior. By using a Map you get sparse data storage improvement over arrays and maintain constant time access. If the data isn’t sparse, this mechanism would use more memory proportional to the number of elements. Iteration time is capacity proportional which is slightly inferior to an arrays constant time. Also, array copying requires a small amount of additional custom code to duplicate the Elements, i.e., a copy constructor.

This approach is simpler than using multiple arrays since it minimizes the indexing to a single implementation vs. an indexing implementation for each array type.

If it is necessary to return some particular values when no data exists, decorate or extend the Map or the Element class and provide the custom behavior.

For Map base implementation utilize the “x” + “y” indices as the id for equals and key for hashCode. Create a …

Linux filesystems

No built-in int[] to List

The following creates a List<int[]> as if int[] were int[][]


int[] ints = new int[] {1,2,3};
final ArrayList<Integer> list =
new ArrayList<Integer>(ints.length);
for (final int i : ints) {
list.add(ints[i]); //autoboxing
return Collections.unmodifiableList(list);

Logging a stacktrace

try {
Something that throws an Exception
} catch (final XxxException e) {
LOG.error("Some message", e);


try {
Something that throws an Exception
} catch (final XxxException e) {
final StringWriter w = new StringWriter(10000);
final PrintWriter pw = new PrintWriter(w);
// Do something with 'w' which now
// contains the formatted stacktrace

Java Real-Time System RTSJ



Requires one of the following OSs

Ubuntu with Real-Time kernel
Solaris 10 Update 4/5
Red Hat Enterprise MRG
SUSE Linux Enterprise Real-Time 10 (SP2)


15 mS latency
5 mS jitter

Ubuntu Real-Time WIKI
Real-Time Linux WIKI
HOWTO: Build an RT-application - causes of latency/jitter and reduction hints (SMI, USB mouse & keyboard, page-faults, file handling)

To update Ubuntu search for linux-rt in Synaptic Package Manager and install, add to /menu/grub/menu.lst

Set /tmp to use tmpfs
In /etc/fstab add

none /tmp tmpfs defaults 0 0

Dual-boot Solaris