reading….

“Even when reading is impossible, the presence of books acquired produces such and ecstasy that the buying of more books than one can read is nothing less than the soul reaching towards infinity… we cherish books even if unread, their mere presence exudes comfort, their ready access, reassurance.” — A.E. Newton

Note to self about SessionFactory

I was very pleased about how well the WebService code was working. I had finally gotten the process of changing the WS code as well as the C++ client code nailed down. As I started testing I noticed that JBoss/Hibernate started fail and complain about too many connections.

It turns out there are a lot of people that have had the same issue. The recommended solutions are:

1. Use finally block to make sure sessions are closed.

2. Use a connection pool other then the default. C3P0 is highly recommended.

I went through the code line and by and made sure sessions were being closed. Configuring a new connection pool wasn’t as straight forward as I would have hoped. After starting JBoss I noticed complaints about C3P0 vs Hibernate properties.The solution seems to be to add “hibernate” to the property name as shown below.

Original:

<!– start c3p0 connection properties –>
<property name=”c3p0.min_size”>10</property>

New:

<!– start c3p0 connection properties –>
<property name=”hibernate.c3p0.min_size”>10</property>

Even after doing all this I still had the “too many connections” problem.  I reduced the Ws code to a few lines, open a session and close a session. And still I had “too many connections” .

Then the “big dummy” light came on. I was creating a new sessionFactory each time a made a WS call!

SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();

Session session = sessionFactory.openSession();

I moved the sessionfactory creation to the constructor and made sessionFactory a member variable. After re-deploying it works perfect and is much faster.

This is one case where having code reviews or at least a second set of eyes on the code would have helped.

Saving State..

There isn’t an application today that doesn’t have a “Preference” or “Settings” section. The GRITS viewer and image processing application are no exception. The viewer application needs to preserve information such as “work offline”, “window transparency level”, and “image translation” values. For a long time this was done by reading and writing to a file. Windows programmers eventually achieved this functionality using the system registry. Java developers now have the Preferences API.

The GRITS project is using QT in a C/C++ environment and I was dreading have to deal with saving state or preference information. But then I discovered “QSettings“.

The QT developers think of everything. QSettings lets me store and retrieve information without having to code for each platform. On Windows it uses the system registry, on the Mac OS, XML files  and on Unix INI files are used. QSettings uses simple key/value pairs but also gives the ability to store data in a custom format. Using this is very straight forward.

To store data first create a QSetting object. Then call beginGroup(). “setValue()” adds the information and “endGroup()” completes the process.

QSettings settings();

settings.beginGroup();

settings.setValue();

settings.endGroup();

Here is an example of how I used this to store the window transparency setting.

QSettings settings(”GritsSettings”, “Preferences”);

settings.beginGroup(”viewersettings”);

settings.setValue(”windowTransparency”, windowTransparencySlider->value());

settings.endGroup();

Here is how the information appears in the registry.

registry

Since I need to access this data from various parts of the application I created a Preferences object that hides the QSetting details. I can simple user prefs->getTransparency() or setTransparency() to do the work for me.

Its not too difficult to see how one could use this to store the location and state of windows or other pieces of application information.

gsoap with ssl – Part 2

The gsoap issue wasn’t as straight forward as expected, surprise! As I stated last time “wsdl2h” worked fine when connecting the to the external server either with or without ssl. But the service address wasn’t correct.  The JBoss server is running behind Apache and this must be causing the service name to use the localhost address.

From the wsdl:

“<service name=”MyWebService”>
<port binding=”tns:MyWebBinding” name=”MyWebPort”>
<soap:address location=”http://127.0.0.1:8080/Myweb/MyWebService”/>
</port>
</service>”

In the MyWeb.h file created from running wsdl2h I found:

“@section MyWebBinding_ports Endpoints of Binding  “MyWebBinding”
-http://127.0.0.1:8080/Myweb/MyWebService”

I  changed the url to:  “@section MyWebBinding_ports Endpoints of Binding  “MyWebBinding”
-http://university.edu/Myweb/MyWebService”

and ran soapcpp2. It didn’t work. The endpoint in the WebBindingProxy file still defaulted to the local host.  To get around this I initialized the endpoint to the correct value in the MyWebBindingProxy_init method:

“void MyWebBindingProxy::MyWebBindingProxy_init(soap_mode imode, soap_mode omode)
{

soap_imode(this, imode);
soap_omode(this, omode);
soap_endpoint = “http://university.edu/myweb/MyWebService“;
static const struct Namespace namespaces[] =……..”

and it works..almost. The ssl connection still isn’t working. so much for my hoping this would “just work”. Back to ssl……

P.S.

I started out using gsoap without any options. I’d suggest using the “-nname and -Nname” options with wsdl2h to rename the prefix. As it is now all of  objects and methods default to “ns__”. While this is fine for now it make for ugly code and in the future some will hate me if I don’t change it.

FORTUNE: How to build a (strong) virtual team

CNN Money FORTUNE

By Anne Fisher

“In a world where fewer and fewer employees work in the same location as their bosses, IBM is figuring out how to bring together far-flung coworkers.

NEW YORK (Fortune) — Leo Mendoza is a typical IBM sales rep. Based in Chicago, he starts his day with a 5:45 a.m. swim at a local health club, then usually hits the road by 7:15 to see clients in Milwaukee or Racine. A couple of days a week, he works from home. How often does he see his boss in person? Maybe once a month, maybe less.

“Going mobile like this made me nervous at first,” says Mendoza. “But after two or three months, that went away. I realized, hey, I can get my work done and make my numbers without going in to the office.”

If you’re like most managers these days, you have more and more people like Mendoza reporting to you — that is, people you rarely lay eyes on. Consider: A 2008 study by high-tech think tank Nemertes Research found that 90% of U.S. employees now work somewhere other than headquarters, and 84% work in a different location than their bosses.

The years 2003 to 2008 saw an 800% jump in the number of “virtual employees”. That group includes road warriors who travel constantly, telecommuters who work from home, and people in one-or-two-person offices spread out all over the globe.

Collaborating with peers and team leaders separated by vast distances is made possible by technology, of course, but virtual managers are discovering that technology alone doesn’t build teams.

The ’90s marketing catchphrase “high tech, high touch” applies here too: The more dazzling the gadgets people have at their disposal, the more they crave ordinary human contact — or a close facsimile of it.

About 40% of IBM’s 400,000 employees are now virtual. Since 1995, when IBM (IBM, Fortune 500) first began encouraging its employees to telecommute, the company has been working on building a sense of personal connection among far-flung workers.

“Humans are social animals. Without a real sense of community, most people just don’t do their best work,” says Dan Pelino, general manager of IBM’s global health care and life sciences division.

Social networking that’s encouraged

To combat a widespread feeling that IBM stood for “I’m By Myself”, as an in-house joke had it, Pelino brought back IBM Clubs, an old company tradition that had been allowed to fall by the wayside.

The clubs, now active in several hundred cities in 30 countries, bring employees together for family events, like trips to the zoo, as well as for work-related meetings like coaching and mentoring sessions with senior executives.

Sales rep Leo Mendoza says the Chicago club has helped him bond with other mobile staffers. Three of them, whom he had befriended at an IBM golf outing, came to his wedding in Colorado, “even though it was a day’s drive for them each way,” he says. “I was really touched by that.”

IBM, this year’s Top Company for Leaders, is also using technology to whittle the distances between people. In 2007, for instance, a task force called OTTO (for Other Than the Office) created informal online networks of virtual employees who share ideas, advice, moral support, and scuttlebutt — just like in-person cubicle mates.

The company added a social networking site called SocialBlue where employees post photos and bulletins about topics like their kids, their dogs, their motorcycles, and what they did over the weekend. It’s a big hit with tens of thousands of IBMers worldwide, from new entry-level hires to senior vice presidents.

Employee surveys show that being able to work far from colleagues without losing touch has boosted employee satisfaction and makes top talent more inclined to stick around. IBM managers say SocialBlue has been a boon to teamwork and productivity — ironic, since the site recreates the kind of water-cooler chitchat that might once have been considered a waste of company time”

CNN: Ten things (OK, 9) I love about telecommuting

I read this on CNN.

pirillo.telecommuting

By Chris Pirillo

“With gas prices inching their way back up and traffic in most metropolitan areas bottlenecking along any rush-hour route, it’s a wonder that the majority of the modern office workforce doesn’t telecommute.

The sad fact is that many bosses and personnel departments refuse to see the value in allowing their underlings the freedom to work from home in spite of the massive cost savings of business overhead (i.e. office space rental, work stations, parking, etc.) and potentially increased productivity.

How can employees be working, these short-sighted micromanagers muse, if they’re not monitored for every second they’re on the clock? Who’s going to make sure they’re taking their allotted 30-minute lunches and 10-minute breaks? Who will crack the whip when the personal phone calls and water cooler chit-chat get out of hand?

Stuck in the mindset of the 19th-century business model like Dickensian Scrooges, these uninformed overseers fail to see how grown adults could possibly be trusted to monitor their own work habits and get their jobs done without the “benefit” of managerial…guidance.

They don’t understand how constant meddling (i.e., calling endless meetings, tapping their watches parentally when employees return from lunch two minutes late, interrupting the general flow by introducing empty priority items over work already in progress, etc.) hinders — rather than stimulates — overall office morale and productivity.

Let’s say your job really is something that doesn’t require you to be shackled to a desk in some office loft’s cubicle sprawlscape. You have a daily checklist of tasks that need to be done and, regardless of whatever distractions may come your way, you’ve got the discipline to make sure you get those tasks crossed off before the personnel department’s officially permitted quitting time.

What do you say to a boss who, for no sane reason on God’s green earth, resists a sensible appeal for allowing you to telecommute? It’s tempting to parrot the immortal words of Redd Foxx’s Fred Sanford and say: “You big dummy!”

But don’t. Don’t. Sure, it’d probably save you the agony of your daily commute, but…

On the other hand, if you’re lucky enough to work in a place that does allow you to telecommute but the person who needs the most convincing is you, here are some of the best reasons I can come up with (maybe you’ll think of more — if so, drop me a line and share!):

1. You’ll save money on gas and car repairs, and possibly insurance since you’ll be traveling less miles every day.

2. No more random interruptions from the office busybody.

3. Worried about not having enough social interaction? Do your work at home and hang out with people of your own choosing afterward instead of whoever you get stuck with all day long at the office! Sure, those social circles may overlap and you might actually enjoy the company of people with whom you happen to work, but my point here is that telecommuting gives you options.

4. Spend a good chunk of your day on the Internet? The office will likely pay for your home broadband connection!

5. Need to share a presentation with someone? Think about putting it up on SlideShare.

6. Need to collaborate on a spreadsheet? Use Google Docs! Stop sending file attachments, already! Seriously, if you’ve learned nothing else from this article, it’s the benefit of using a service like Google Docs.

7. Need to look at someone’s desktop remotely? I bet your company’s system administrator has a tool for the job.

8. Need to take notes with a group, even if you’re not in the same room together? Check out Etherpad.com.

9. Need some kind of radio playing in the background, just for that old-time officey feel? Point a Web browser to Pandora.com or Last.fm. You can define your own stations instantly, based on music and artists you love.

10. Monitor your eating habits, because (I’m telling you) you’ll snack more at home than you do at work — it’s too convenient. Hey, I had to throw in at least one caveat, right?

Still reading this at the office in spite of being offered the option to telecommute by your progressive, 21st-century, forward-thinking company? What the heck are you waiting for, you big dummy?”

gsoap with SSL

Yesterday we managed to get the webservice configured so that its visible outside to the outside world. I didn’t do much but D.J Merrill at Bowdoin College was able to work his magic. The only issue is that my client application is using gsoap (C++ environment)  and apparently doesn’t include ssl as part of the win32 binaries. At least the wsdl2h utility isn’t built that way.

First off one needs something like openssl installed. Getting this downloaded was easy. To build it you need Perl. Great, I removed that a while ago as I wasn’t using it. Back to ActivePerl and get that. With Perl installed building openssl was simple, just follow the directions under install.w32.

Back to rebuilding gsoap. The Visual Studio project included doesn’t seem to work, at least it doesn’t within the limits of my current attention span. Lets try cygwin. Much better,run configure, make, and make install. The only issue is that I didn’t change the install folder so everything gets put in under the cgywin folders. No big deal just copy the required files where I need them. I’ll have to fix this later.

Now the wsdl2h works fine. It connects to the webservice located at the college!  Next, rebuild the app and test……

.NET and Java WebService

Sometimes one does things just to see the result. In this case I wanted to see how it would be to access a Java web service from a .NET C# application. The client side of GRITS project uses VTK along with QT. While there are .NET wrappers for VTK I haven’t tried them. Besides the QT/VTK combination works on Apple as well so .NET wouldn’t bring anything to the table. But I still wanted to see. The WebService is running on a JBOSS Application server with Apache as the Web server. Hibernate provides the object/relational persistence and query service.

I am using VS 2008 and its fairly straight forward.

The first step is to create a new ASP.NET web site.

VS-1

The second step is to add a Web Reference.

VS-2

On the Web Reference screen enter the url of the web service wsdl.

VS-3

After the processing is done you can see a list of services that were found. So far this is exactly what I was hoping for.

VS-4

The next step is to add code that will connect to the service. Since we named the service Grits  we can do the following.

using Grits; // add name space

public partial class _Default : System.Web.UI.Page
{
GritsWebService proxy;  // create a service proxy variable

protected void Page_Load(object sender, EventArgs e)
{
proxy = new GritsWebService();

}

VS-5

And finally call the service. At this point nothing will happen. Watching the JBOSS console window shows no activity.One query that I know will work with out VTK is “findRegionByExtent”.  This call takes a user name and six points that will define a bounding volume.

Selecting “GritsWebService” and then “Go to Definition” gives a list of all of the functions along with their parameters and return  values.

VS-5.5

The function “findRegionByExtent” takes a “findRegionByExtent” type as a calling parameter and returns an “areaRegionInformation” array.

VS-6

Using “Go to Definition” we can see how they are constructed.

VS-7

VS-8

The  “findRegionByExtent” type  isn’t very descriptive, its just indicates seven args. I’ll need to address this on the Web service side so that it uses more descriptive values. Since I created the beast I know that arg0 is the user name and args 1-6 are xmin,xmax,ymin,ymax,zmin and zmax. These describe the volume in which we want to search.

The return value “areaRegionInformation” returns a set consisting of genename, spotname, stagename and a set of points. There will be one set for each unique gene,spot,stage combination that lies within the bounding volume.

Here is the code that sets up and makes the call. I added six points that I know will provide results.

VS-10

Running the app in the VS debugger I see a response in the JBoss console window indicating that two “spots’ were located:

INFO  [STDOUT]  xmin -70.33 xmax -50.33 ymin 62.93 ymax 82.93 zmin -144.03 zmax -122.03
INFO [STDOUT] findRegionByExtent– The number returned is :2

In the VS debugger with a break point set we can see the results(part of them) returned from the service.The length of the array “test” is 2 and the first genename is “Calbindn”  so I know that is working.

VS-12

The next step would be to display this results. This would require the .NET version of VTK, maybe later but I wonder about  the iPhone…..?

Slicing the model.. oops

There is a tool that is used to slice up the model. It works along the same lines as what was used to fix the scaling problem. So far I have been working with only one data set. A few days ago I received a new model and started to process it. The first step is to “slice” the model. Of course this didn’t work. My biggest fear was that the tool wasn’t robust enough and this new model was breaking something. After spending hours(and hours) trying to determine what was causing the troubles maybe it was time to look at the model data .

The model was created in 3D studio, which I don’t own. You know how expensive 3D studio is? I have a 3D tool called Milkshape and it will import 3D files. While I couldn’t fix the issue I could see there was something wrong. I resorted to downloading a trial version of 3D.

The white object shown below isn’t supposed to be there.

3dmax-1

I was able to remove the extra object without messing up the remaining data.

3dmax-2

The slicer works fine now.

slice-2

Image scaling… redo

I have had this issue where the images didn’t align correctly with the model. It turns out that only the first one(Z=0). Th answer is that the model varies in X,Y along the Z axis. The bounding box that is used to scale the image to the model must be recalculated for each image according to its position on the model. Don’t why I didn’t see this before.

The trick is to extract a slice from the model at the desired Z position. VTK does this very nicely. Then get the bounding box for the slice. This is what we will use to scale the image.

Below is a slice of the model(blue) mapped onto the model.

model slicing

Using this new scaling process here are some results. Its clear that the images fit the model much better then before.

image scaling 1

image scaling 4

image scaling 2

←Older