Posts

Showing posts from January, 2012

Lock Free Stack Implementation in C#

This method compares destination to currentValue, and if they're equal sets destination to newValue and returns currentValue unchanged.

If they aren't equal it just returns the value of destination.

This is done in an atomic fashion i.e. no other thread can interrupt it.  In carrys out this in atomic fashion becasue its executed at hardware level with a single nstruction CMPXCH instruction.


public class LockFreeStack<T> {
    private volatile StackNode<T> m_head;

private static bool CAS(ref Node<T> destination, Node<T> currentValue, Node<T> newValue)
{
   return
         currentValue== Interlocked.CompareExchange<Node<T>>(ref destination, newValue, currentValue);
 }


    public void Push(T item) {
        StackNode<T> node = new StackNode<T>(item);
        StackNode<T> head;
        do {
            head = m_head;
            node.m_next = head;
        } while (m_head != head || CAS(ref m_head, node, head) != head);
   …

Using Microsoft .NET (VS2010) with WebSphere Message Broker V8

I recently upgraded from MB7 and MBT7 to MB8 and MBT8

One of the first features I wanted to try out was the ability for MBT8 to import a .NET assembly

All was fine on the MBT8 side of things and I was able to create my basic Message Broker Project

However when I launched Visual Studio C# and selected New Project

I could not find any project templates for Message Broker

To install these template project wizards I had to run the following from a command prompt

 C:\Program Files\IBM\WMBT800\wmbt\vsixinstall.bat

I assume the vsix stands for Visual Studio Extensions

And it worked

Ruby Talking to MBT SoapInput Node

Image
This is a basic Ruby Script to engage with SoapInput Node running on localhost 7800 with MBT

require 'net/http'
require 'net/https'

# Create te http object
http = Net::HTTP.new('localhost', 7800)
http.use_ssl = false
path = '/acmeOrders/WADDR/ProcessOrders'

# Create the SOAP Envelope
data = <<-EOF
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<submitPORequest xmlns="http://www.acmeOrders.com/OrderService">
<partNo xmlns="">11</partNo>
<partQuantity xmlns="">0</partQuantity>
<personName xmlns="">
<firstName>Trevor</firstName><lastName>O Connell</lastName>
</personName>
<address xmlns="">
&l…

Testing MBT SoapInput Node from VB.NET

Image
Once you've loaded and deploy the SOAP Node Samples project you can add a web service reference in Visual Studio 2088 (Project / Add Web Reference). Enter the URL http://localhost:7800/acmeOrders/WADDR/ProcessOrders?wsdl

In my case I added the reference name "orders"

So from within my Visual Basic.NET code

Dim vOrders As New orders.OrderService()
Dim vRequest As New orders.submitPORequest()
Dim vResponse As New orders.submitPOResponse()
vRequest.partNo = tPartNo.Text
vRequest.address = New orders.submitPORequestAddress()
vRequest.personName = New orders.submitPORequestPersonName()
vRequest.personName.firstName = tFirstname.Text
vRequest.personName.lastName = tLastname.Text
vRequest.address.street = tStreet.Text
vRequest.address.zipCode = tZipCode.Text
vRequest.address.city = tCity.Text
vResponse = vOrders.submitPO(vRequest)
tStatus.Text = vResponse.orderStatus


Below is a screenshot. Its nothing too difficult but it just gets your VB.NET application talking with an MBT Message Flow.

MBT/ESQL : Reduce CPU Load - Access nth Element in Array using Reference

How to reference variables to access elements of an array.

DECLARE ref REFERENCE TO OutputRoot.XML.Invoice.SalesOrders.Item[1];

WHILE LASTMOVE(ref)=TRUE DO
SET ref = ref + 1;
MOVE ref NEXTSIBLING;
END WHILE;

Cloud based logging service

Loggly is a cloud based logging service. It helps you collect, index, and store all your log data with the help of Solr

Dynamic Email from MBT/ESQL

CREATE COMPUTE MODULE Send_Mail
CREATE FUNCTION Main() RETURNS BOOLEAN
BEGIN
-- CALL CopyMessageHeaders();
-- CALL CopyEntireMessage();

CALL CopyMessageHeaders();

-- Add recipient information to the EmailOutputHeader
SET OutputRoot.EmailOutputHeader.To = 'info@dtm.ie';

-- Add sender information to EmailOutputHeader
SET OutputRoot.EmailOutputHeader.From = 'trevor.oconnell@dtm.ie';


-- Add subject to EmailOutputHeader
SET OutputRoot.EmailOutputHeader.Subject = 'Test.';

-- Add SMTP server information to the LocalEnvironment
SET OutputLocalEnvironment.Destination.Email.SMTPServer ='mail.dtm.ie:25';
SET OutputLocalEnvironment.Destination.Email.SecurityIdentity ='MyIdentity';

-- Create a new message body, which will be sent as the main text of the email.
SET OutputRoot.BLOB.BLOB = CAST('This is the new text for the body of the email.' AS BLOB CCSID 1208);  

RETURN TRUE;
END;

CREATE PROCEDURE CopyMessageHeaders() BEGIN
DECLARE I INTEGER 1;
DECLARE J INTEGER;
SET J = …

What's wrong with certificate warnings? How can we abolish them?

A new proposal called "Sovereign Keys", which is intended to resolve weaknesses in the way that encrypted Internet protocols perform authentication for applications such as web servers and mail servers.

Hopefully get rid of those nasty certificate warning messages that no one except techies understand, and even for techies they can be a struggle at times.
More on Sovereign Keys

MBT/ESQL to Modify XML element names

<Shares>
<Kerry>5</Kerry>
<Fexco>12</Fexco>
<AIB>40</AIB>
</Shares>

Change AIB to BOI instead, Feed XML in to XMLNS format MQ Input Node, Create  MQIN

CREATE FUNCTION Main() RETURNS BOOLEAN
BEGIN
-- CALL CopyMessageHeaders();
-- CALL CopyEntireMessage();
SET OutputRoot.XMLNS.Data = ROW(InputBody.Shares.Kerry,
InputBody.Shares.Fexco,
(InputBody.Shares.AIB) AS BOI);
RETURN TRUE;
END;

Receive output in MQ Output Node MQOUT

<Data>
<Kerry>5</Kerry>
<Fexco>12</Fexco>
<BOI>40</BOI>
</Data>

Basic Receive Message to MQ with Java and IBM MQ JMS

package my.mq.samples;

import javax.jms.JMSException;
import javax.jms.Session;
import javax.jms.TextMessage;
import com.ibm.mq.jms.MQQueue;
import com.ibm.mq.jms.MQQueueConnection;
import com.ibm.mq.jms.MQQueueConnectionFactory;
import com.ibm.mq.jms.MQQueueReceiver;
import com.ibm.mq.jms.MQQueueSession;
import com.ibm.msg.client.wmq.WMQConstants;

public class MQReceive {

public static void main(String[] args)
{
try {
MQQueueConnectionFactory cf = new MQQueueConnectionFactory();
cf.setHostName("localhost");
cf.setPort(1414);

cf.setIntProperty(WMQConstants.WMQ_CONNECTION_MODE, WMQConstants.WMQ_CM_CLIENT);

cf.setQueueManager("QM_GRIDSERVER");
cf.setChannel("SYSTEM.ADMIN.SVRCONN");

MQQueueConnection connection = (MQQueueConnection) cf.createQueueConnection();
//MQQueueConnection connection = (MQQueueConnection) cf.createQueueConnection("username","password");

MQQueueSession session = (MQQueueSession) connection.createQueueSession(false, Session.AUTO…

Basic Send Message to MQ with Java and IBM MQ JMS

package my.mq.samples;

import javax.jms.JMSException;
import javax.jms.Session;
import javax.jms.TextMessage;

import com.ibm.mq.jms.MQQueue;

import com.ibm.mq.jms.MQQueueConnection;
import com.ibm.mq.jms.MQQueueConnectionFactory;
import com.ibm.mq.jms.MQQueueSender;
import com.ibm.mq.jms.MQQueueSession;
import com.ibm.msg.client.wmq.WMQConstants;

public class MQSend {

public static void main(String[] args)
{
try {
MQQueueConnectionFactory cf = new MQQueueConnectionFactory();
cf.setHostName("localhost");
cf.setPort(1414);

cf.setIntProperty(WMQConstants.WMQ_CONNECTION_MODE, WMQConstants.WMQ_CM_CLIENT);

cf.setQueueManager("QM_GRIDSERVER");
cf.setChannel("SYSTEM.ADMIN.SVRCONN");

MQQueueConnection connection = (MQQueueConnection) cf.createQueueConnection();
//MQQueueConnection connection = (MQQueueConnection) cf.createQueueConnection("username","password");

MQQueueSession session = (MQQueueSession) connection.createQueueSession(false, Session.AUTO_ACKN…

Working with CSV files made simple with Websphere MBT and DFDL

Working with CSV files and mapping them from/to any of the WebSphere Message Broker domains is a lot easier with the support for DFDL files in version 8.0

Using DFDL files you can easily create message flows to parse and serialize CSV messages to and from any of the WebSphere Message Broker domains.

http://publib.boulder.ibm.com/infocenter/wmbhelp/v8r0m0/index.jsp?topic=%2Fcom.ibm.dfdl.editor.messagebroker.doc%2Fdf20071_.html

For example I'd a project where I needed to capture order information from several third party marketplaces.
Each marketplace offered different methods for accessing the most recent order information for our account. For example
Web Services Interface FTP  Email
In addition each marketplace used a different format sometimes XML based and sometimes CSV based to describe orders placed.
Using the DFDL its a lot easier to create a mapping  between these various marketplace formats and in turn creates a standard output XML format that is suitable for our in house ERP sys…

Configure EmailOutput Node in Websphere Message Broker Toolkit

Launch a message broker command console and issue the following commands

mqsicreateconfigurableservice MB7BROKER –c SMTP –o SMTPAlias

mqsichangeproperties MB7BROKER –c SMTP –o SMTPAlias –n serverName –v mail.trevoroconnell.com:25

mqsichangeproperties MB7BROKER –c SMTP –o SMTPMyAlias –n securityIdentity –v mySecurity

mqsisetdbparms MB7BROKER -n securityIdentity –u trevor.oconnell@trevoroconnell.com -p trevor

Then within the WMBT, add your EmailOutput Node to the message flow
Open properties for the EmailOutput Node and for SMTP Server enter the alias SMTPAlias

Cloud Fault Tolerance with JClouds

JClouds makes building highly available cloud based applications a lot easier.  JClouds creates an abstraction layer that is independent of the underlying cloud infrastructure.

So for example JCloud Compute API allows you to easily interface with infrastructure cloud providers such as Amazon EC2 and VMWare vCloud etc using a single standard API.

So basically if you app runs across multiple computer nodes across multiple cloud infrastructure providers you only need to worry about learning one API to manage computer nodes i.e. the JCloud ComputeNode API.

http://www.jclouds.org/documentation/userguide/compute

Automating File Transfers - Multiple Directories / Lots of Files

One of the big disadvantages of FILEZILLA is its poor command line interface (CLI) support.  This makes it very unsuitable for use in an environment where you need to script automated file transfer routines

For example working on a recent project I've had to design a routine to automate the transfer of files (300,000 approx) from a local server across several remote servers.
Based on a defined local directory structure these files would be transferred in to specific remote folders on each remote server.
So I needed something that would allow me

1. Connect to a specific remote server and authenticate 2. Prevent interactive prompts i.e. asking user to confirm, retry or abort 3. Programatically select a local directory on the local server 4. Programatically select a local directory on the remote server 5. Transfer specific file types from the local server to that remote server 6. Close to the connection 7. Move to the next folder on the local server and repeat .....
While I could accomplish…

Java Send / Read from Remote MQ Queue on CentOS Linux

package my.mq.samples;

import javax.jms.JMSException;
import javax.jms.Session;

import com.ibm.jms.JMSMessage;
import com.ibm.jms.JMSTextMessage;

import com.ibm.mq.jms.MQQueue;


import com.ibm.mq.jms.MQQueueConnection;
import com.ibm.mq.jms.MQQueueConnectionFactory;
import com.ibm.mq.jms.MQQueueReceiver;
import com.ibm.mq.jms.MQQueueSender;
import com.ibm.mq.jms.MQQueueSession;
import com.ibm.msg.client.jms.*;
import com.ibm.msg.client.services.*;
import com.ibm.msg.client.wmq.WMQConstants;

public class MQConnect {


public static void main(String[] args) {

    try {
      MQQueueConnectionFactory cf = new MQQueueConnectionFactory();
      cf.setHostName("82.195.136.246");
      cf.setPort(60000);

      cf.setIntProperty(WMQConstants.WMQ_CONNECTION_MODE, WMQConstants.WMQ_CM_CLIENT);

      cf.setQueueManager("dtm.queue.manager");
      cf.setChannel("SYSTEM.DEF.SVRCONN");

      MQQueueConnection connection = (MQQueueConnection) cf.createQueueConnection("T…

Setting Up a Websphere MQ Listener on CentOS

Step 1 - Add the following to /etc/services
-bash-3.2$ vi /etc/services
WebsphereMQ      1414/tcp    # WebSphere MQ channel listener

Step 2 - Create a service configuration file in /etc/xinetd.d
-bash-3.2$ vi /etc/xinetd.d/websphere # place the following in it

service WebsphereMQ
{
   socket_type     = stream
   wait            = no
   user            = mqm
        port                            = 1414
   server          = /opt/mqm/bin/amqcrsta
   server_args     = -m dtmtest.queue.manager
   log_on_failure  += USERID
}

Step 3 - Restart xinetd -bash-3.2$ service xinetd restart

Step 4 - Check your logs for errors -bash-3.2$ tail /var/log/messages

Step 5 - Check its listening on port 1414 -bash-3.2$ netstat -an | grep 1414

Getting Started with Websphere MQ on Linux CentOS

Install Procedure for MQ Series 7.1.0-0

Step 1 - Create Working Folder
-bash-3.2$ mkdir $HOME/MQ
-bash-3.2$ cd $HOME/MQ

Step 2 - Download
-bash-3.2$ wget https://www15.software.ibm.com/sdfdl/v2/fulfill/CI50ZML/Xa.2/Xb.JSiMj8YMb5GyHPzC8QrNFjOjmKulz6rMpstKQz2u2A/Xc.CI50ZML/CI50ZML.tar.gz/Xd./Xf.LPr.D1VK/Xg.6326855/Xi.ESD-WSMQ-EVAL/XY.regsrvs/XZ.xZgIo09btSUWIzRzk9IMAGmpv4I/CI50ZML.tar.gz

Step 3 - Run License Acceptance Script
-bash-3.2$ ./mqlicense.sh -accept

Step 4- Install MQ Runtime Environment
-bash-3.2$ rpm -ivh MQSeriesRuntime-7.1.0-0.i386.rpm

Step 5 - Install MQ Server
-bash-3.2$ rpm -ivh MQSeriesServer-7.1.0-0.i386.rpm

Step 6 - Install MQ Samples need these for testing

-bash-3.2$ rpm -ivh MQSeriesSamples-7.1.0-0.i386.rpm


Step 7 - Lets Test
Login as super user root
-bash-3.2$ su - mgm
-bash-3.2$ cd /opt/mqm/bin

-bash-3.2$ ./crtmqm -q dtm.queue.manager # create a queue manager
-bash-3.2$ ./strmqm # start the queue manager
-bash-3.2$ ./runmqsc # run MQMS commands
define qlocal (dtm…

Stackato Micro Cloud will continue to be free

Stackato will continue free of charge for developers to use as their own private Platform-as-a-Service (PaaS) solution on a single node.

The company behind Stackato, ActiveState, all their products use open source community driven proujects and solutions.

Stackato is based on the open source Cloud Foundry project and is a private PaaS that gives developers cloud deployment options for PHP, Java, Python, Ruby, Perl, Node.js, Scala, and Clojure applications.

In short Stackato allows developer design, develop and test cloud based solutions that will either run on an internal private cloud driven by a hypervision such as VMWare or else on an external cloud infrastructure provider IAAS such as Amazon EC2.

With Stackato Micro Clouds developers can design, build, reengineer and test new or existing applications that may be suitable for cloud on their own private cloud.

To learn more go to
http://www.activestate.com/cloud

Java Observer Pattern - Watching Company Share Values

This is a very simple example of using the Observer Design Pattern.

In this instance we have a company share value (subject) i.e. sharevalue. Each company has a defined sharevalue which may/may not change throughout the day.

We then want to notify via the company web site or mobile phones (observers) of any change to this share value.

Share will notify to CompanyWebSite and MobilePhone to disply new share value.

To implement this we have a Subject interface which contains methods for adding, removing and notifying Observers and an Observer interface which contains update(float sharevalue) method which will be called by Subject implementation when a company share value changes.

import java.util.ArrayList;

interface Observer {
       public void update(float tradingvalue);
}

interface Subject {
       public void registerObserver(Observer observer);
       public void removeObserver(Observer observer);
       public void notifyObservers();
}

class Share implements Subject {
       priva…

Configure Database Connection using MyBatis

Step 1: Create a propertiese file and store the relevant MySQL connection details here.

In my case the config.properties file contains the following
username=mysqluser
password=1234mysql
url=jdbc:mysql://localhost/bankrecords
driver=com.mysql.jdbc.Driver

Step 2: Create a configuration.xml file, this should contain all the required information needed to connect to your MySQL instance.  you need to reference the above propertiese file in the XML config file.

< ?xml version="1.0" encoding="UTF-8" ?>
< !DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<properties resource="config.properties" />
<environments default="staging">
<environment id="staging">
<transactionManager type="JDBC"/>
<dataSource type="POOLED">
<property name="driver" value="${driver}"/>
<…

Grid Enable Your Java Applications with GridGain

GridGain is Java based open source middleware for real time data processing and analytics that scales up from one server to thousands of machines.

GridGain is available via open source community edition or enterprise paid edition with bundles of extra features and options.
Getting started with GridGain is simple
import java.lang.*; import java.math.*; import org.gridgain.grid.GridException; import org.gridgain.grid.GridFactory; import org.gridgain.grid.gridify.Gridify;
public class GridTest{
public static void main(String args[]) throws GridException{ GridFactory.start(); try{ System.out.println("My First Grid Test.."); }catch(Exception e){ e.printStackTrace(); }finally{ GridFactory.stop(true); } } }
To Grid Enable Funcitons i.e. allow the Java Byte Code to be moved to a remote node for computation simply add the Java Annotation @Gridify
for example
@Gridify public int compute(int datavalues[], int newdatavalues[], int multiplier)
{ for(int i=0; i < datavalues.length ; i++) {  newdatavalues[i] =…