Thursday, December 18, 2014

Generic Queue & Consumer Implementation using Java

Here I have implemented a generic queue and consumer using Java.


Java Implementation Source Code
https://github.com/harsha1979/lightweightqueue.git


 //Create an ExecutionEngine and start.

boolean isAutoStart = false ;
boolean isAutoRestart = false ;


//Time Delay in Millisecond
int timeDelay = 100 ;
int queueLength - 100 ;

//ExecutorImpl is an implementation of the Executor to do the task when the executor do execute.

Executor executor = new ExecutorImpl();

ExecutionEngine executionEngine =  new ExecutionEngine<CustomBean>(executor,isAutoStart,        isAutoRestart,timeDelay,queueLength);

executionEngine.startEngine();

//Put an element to the queue
CustomBean customBean = new CustomBean();
executionEngine.getSynchQueue().put(customBean);

Data Source create on WSO2 products in remote manner

In WSO2 products , we can configured DataSources with lot of features. We can do it using Admin Console in those products.

But sometimes we want to do it remotely like in automated deployment enlivenment. Then we can use a service to that provided by the Admin Services.

Using curl command.

curl -k -u admin:admin -d @datasourceconfig.xml -H "Content-Type: application/xml action=addDataSource" https://hostname:9443/services/NDataSourceAdmin

datasourceconfig.xml


<xsd:addDataSource xmlns:xsd="http://org.apache.axis2/xsd"
    xmlns:xsd1="http://services.core.ndatasource.carbon.wso2.org/xsd"
    xmlns:xsd2="http://core.ndatasource.carbon.wso2.org/xsd">
    <xsd:dsmInfo>
        <xsd1:definition>
            <xsd1:dsXMLConfiguration>
                   <![CDATA[<configuration>
                  <url>jdbc:mysql://localhost:3306/dbname</url>
                  <username>root</username>
                  <password>root</password>
                  <driverClassName>com.mysql.jdbc.Driver</driverClassName>
                  <maxActive>50</maxActive>
                  <maxWait>60000</maxWait>
                  <testOnBorrow>true</testOnBorrow>
                  <validationQuery>SELECT 1</validationQuery>
                  <validationInterval>30000</validationInterval>
                  </configuration>]]>
            </xsd1:dsXMLConfiguration>
            <xsd1:type>RDBMS</xsd1:type>
        </xsd1:definition>
        <xsd1:description>description</xsd1:description>
        <xsd1:jndiConfig>
            <xsd2:name>... JNDI Name here ..</xsd2:name>
            <xsd2:useDataSourceFactory>false</xsd2:useDataSourceFactory>
        </xsd1:jndiConfig>
        <xsd1:name>... DataSourceName Here ..</xsd1:name>
        <xsd1:system>false</xsd1:system>
    </xsd:dsmInfo>
</xsd:addDataSource>