Friday, February 16, 2007

How To: Implement RMI from scratch

The java.lang.reflect.Proxy class will let you provide an arbitrary implementation for an interface.

So, start with that on the client. Figure out how to produce a factory for interface objects. Understand how the proxy invocation works.

Then, create a socket connection to the server. Wrap it with an ObjectInputStream/ObjectOutputStream.

Now you need to define a protocol between client and server. For example, let's say that the client sends an integer object ID, followed by a method name, followed by an array of parameters. The server needs to find the object, and invoke the appropriate method. Then it needs to send the result back to the client.

Then you can get into distributed GC ...

source: java dev forums

Friday, February 09, 2007

JSP: custom tag to modify its body

This is a skeleton of what is needed to build a custom jsp tag which does something to its body. For example a tag could change the urls of all the links found in its body.

make a file called CustomTag.tld and put it into WEB-INF:

use it like this on your JSP:
<%@ taglib uri="com.mycompany.CustomTag" prefix="x"%>

here is some stuff inside the tag!
<c:out value="${someparam}"/>

How to make a redirect servlet

make a servlet which calls the following method on doPost() and on doGet()

Wednesday, February 07, 2007

improve eclipse performance in windows

this eclipse plugin forces windows keep eclipse in memory / reduces thrashing

UNIX: list what sudo permissions you have

> sudo -l
You may run the following commands on this host:
(root) /usr/local/apache/bin/
(root) NOPASSWD: /app/teamsite/iw-home/opendeploy/bin/iwsyncdb.ipl
(root) NOPASSWD: /etc/init.d/smb
(root) NOPASSWD: /usr/local/samba/bin
(root) NOPASSWD: /bin/vi /etc/group
(root) NOPASSWD: /usr/local/bin/top
(root) NOPASSWD: /bin/vi /etc/group
(root) NOPASSWD: /usr/bin/ls
(root) NOPASSWD: /usr/ucb/vipw
(root) NOPASSWD: /usr/local/bin/top
(root) /bin/tail

Javascript: matching with regex

There seem to be 3 ways to use regular expressions in javascript:
var val = document.getElementById("some_id").value;
val.replace(/^\s+|\s+$/g, ""); //trim using regex
var alpha = /^[A-Za-z]+$/ ;
var val = document.getElementById("some_id").value;
//val matches alpha
var val = document.getElementById("some_id").value;
var alpha ='((?:[a-z][a-z]+))'; // Word 1
var p = new RegExp(alpha,["i"]);
var m = p.exec(val);
if (m.length>0)
var word=m[1];
//word is the capture group 1
if anyone knows a better way, feel free to share.