The Age of Spiritual Machines

Finished “The Age of Spiritual Machines: When Computers Exceed Human Intelligence” by Ray Kurzweil a couple weeks ago. If you want a scary view of what the future holds, read this book. I’m not a great book reviewer, so just like all of my other book reviews, here are a couple quotes I thought were thought provoking and/or notable.

“… it illustrated one of the paradoxes of human nature: We like to solve problems, but we don’t want them all solved, not too quickly anyway. We are more attached to the problems than to the solutions.” [pg 1]

On death: “… A great deal of our effort goes into avoiding it. We make extraordinary efforts to delay it, and indeed often consider its intrusion a tragic event. Yet we would find it hard to live without it. Death gives meaning to our lives. It gives importance and value to time. Time would become meaningless if there were too much of it.” [pg 2]

“The only way of discovering the limits of the possible is to venture a little way past them into the impossible.” [pg 14]

“What makes a soul? And if machines ever have souls, what will be the equivalent of psychoactive drugs? Of pain? Of the physical/emotional high I get from having a clean office?” (Esther Dyson on pg 135)

More on ColdFusion & HttpSessionListener interface

Update on yesterday’s post. Here’s a sample listener that implements the HttpSessionListener interface:

****************************************************
package com.mindseye;

import javax.servlet.http.*;
import javax.servlet.http.HttpSessionListener;

/**
* @author Aaron Johnson
* ajohnson@mindseye.com
*
* CFMXHttpSessionListener: An object that implements the HttpSessionListener
* interface, allowing CFMX developers to use session_OnStart and session_OnEnd
* events. This class can only retrieve the J2EE session ID when “Use J2EE
* session variables” is checked in CFIDE –> Administrator –> Memory
* Variables.
*/

public class CFMXHttpSessionListener implements HttpSessionListener {

public void sessionCreated(HttpSessionEvent se) {

// get the session just created
HttpSession newSession = se.getSession();

// do something with the new session (ie: log to db, write to a file, email to a friend
System.err.println(“A new session was created: session = ” + newSession.toString());
System.err.println(“Creation:” + newSession.getCreationTime());

}

public void sessionDestroyed(HttpSessionEvent se) {

// get the session just created
HttpSession newSession = se.getSession();

/* do stuff upon session end, (ie: delete items from this users shopping cart
if you’re persisting items to a db..)
*/
System.err.println(“A session was destroyed: session = ” + newSession.toString());
System.err.println(“Creation:” + newSession.getCreationTime());

}
}

****************************************************
And then to get this class to run, you must add

<listener>
  <listener-class>
    com.mindseye.CFMXHttpSessionListener
  </listener-class>
</listener>

to CFMX\wwwroot\WEB-INF\web.xml and you must copy the compiled class to the CFMX\wwwroot\WEB-INF\classes\com\mindseye\ folder. Additionally, it appears that (and this makes sense) the session we’re getting information about is the J2EE session ID, not the CFID & CFTOKEN. This means that you must have “Use J2EE session variables” checked in CFIDE –> Administrator –> Memory Variables. Restart CFMX and then you can see the results in cfusionmx\runtime\logs\default-err.log

This class would probably be way more useful if it actually did something… like log the start and end times, the id and maybe the servlet context to a database, but each developer will probably want to do something different, so I’ll leave that unfinished. I’m *not* seeing the session_OnEnd fired in my testing… anyone wanna take a guess?

Here’s a sample application_OnStart for CFMX:

****************************************************
package com.mindseye;

import javax.servlet.*;
import javax.servlet.ServletContextListener;

/**
* @author Aaron Johnson
* ajohnson@mindseye.com
*
* CFMXServletContextListener: An object that implements the ServletContextListener
* interface, allowing CFMX developers to use application_OnStart and
* application_OnEnd events.
*/
public class CFMXServletContextListener implements ServletContextListener {

public void contextDestroyed(ServletContextEvent sce) {

ServletContext sc = sce.getServletContext();

// do something on destroy()
System.err.println(“The application ‘” + sc.getServletContextName() + “‘ was destroyed”);

}

public void contextInitialized(ServletContextEvent sce) {

ServletContext sc = sce.getServletContext();

// do something on destroy()
System.err.println(“The application ‘” + sc.getServletContextName() + “‘ was started”);
}
}
****************************************************

Again, same thing, you must copy the compiled class files to cfusion\wwwroot\WEB-INF\classes\com\mindseye\, add a <listener> element to web.xml and restart CFMX. You’ll see the results in cfusion\runtime\logs\default-err.log.

I’d love to hear from Macromedia (or any other Java geeks) as to why I don’t get an results from sessionDestroyed().

ColdFusion & HttpSessionListener interface

Couple weeks ago some guys from Macromedia stopped by to yack with us about what we thought could be improved and/or added to the next version of CFMX. One of the things that came up a couple times was that it would be nice to have session OnStart and OnEnd functionality as well as application OnStart and OnEnd. Reading this month’s Java Developer’s Journal, it has an article on the HttpSession object (I’d link to it, but they charge for their content… too bad, I bet they’d be getting alot more traffic and readers if they’d provide their content for free), which provides multiple listener objects, HttpSessionListener, HttpSessionBindingListener, HttpSessionAttributeListener, and HttpSessionActivationListener. I don’t have CFMX here at home, but it seems like it would be possible to write a class that implements those either of those interfaces (probably the sessionCreated() and sessionDestroyed methods of the HttpSessionListener object), register that class in the web.xml of WEB-INF for your application like this:

<listener>
  <listener-class>
    com.yourApp.yourSessionListener
  </listener-class>
</listener>

Turns out you could do the same type of thing w/ javax.servlet.ServletContextListener [contextDestroyed() and contextInitialized()] and then register:

<listener>
  <listener-class>
    com.yourApp.yourApplicationListener
  </listener-class>
</listener>

in your web.xml and then… hypothetically, you’d have session OnStart, session OnEnd, application OnStart and application OnEnd just like ASP.

I’ll try it out tomorrow, unless you beat me to it.

Content Synchronization Using Rsync

So months ago we were discussing ways of synchronizing files between two servers (for instance the images on a content staging and multiple production servers). My boss kinda put together a list of links for rsync, an open source utility used mainly for quickly transferring files. That email sat in my inbox for the last couple months and only until today did I start trying to get rsync to work. There aren’t any Windows binaries available on the site, which wasn’t a big deal because they gave directions for compiling it here. In order to compile, you need cgywin, so I downloaded and installed that, but the download/install I did for some reason didn’t include make which is required in order to compile rsync. So I went back and re-installed cygwin, this time exploding the options looking for make, only to find that cgywin includes rsync as an option! No need to compile for Windows, just download cygwin and specify that you want the rsync package installed!

I haven’t gotten there yet, but I plan to get rsync running as a service under Windows 2000 on a couple boxes (following these directions). You can find further directions and examples here. I’ll update later on how it works syncing up a couple websites.

On object-oriented design

On object-oriented design: “… Should I derive the class Polyline from the class Point? This has fairly obvious answer. A Polyline is clearly not a kind of point, so it is not logical to derive the class Polyline from the Point class. This is an elementary demonstration of what is often referred to as the ‘is a‘ test. If you can say that one kind of object ‘is a’ specialized form of another kind of object you may have a good case for a derived class…. The complement to the ‘is a’ test is a ‘has a‘ test. If one object ‘has a’ component that is an object of another class, you have a case for a class member. A House object ‘has a’ door, so a Door variable is likely to be a member of the class House.” [pg 254 of Beginning Java 2]