RSS

Monthly Archives: April 2011

Step by Step Guide on How to Install Android SDK Offline (not completely offline)

This guide is for Android developers who are for some reason unable to install Android SDK by following the instruction provided in the official Android Developer page.  Mine is because of my company’s proxy that block this kind of installation.

It’s for Eclipse IDE on Windows box only.  We’ll collect first or download all the necessary files and then glue them together.  I’ll provide and try to update the links here from time to time.

 Required Files:

  • Java Development Kit (JDK)  Download
  • Eclipse – Eclipse 3.6.1 or Helios is the version I’m using.  Download
  • Android Development Tools (ADT) Plugin – custom plugin so we can build Android applications using Eclipse IDE.  Download
  • Android SDK Starter Package – includes the core SDK Tools.  Download
  • Android SDK Tools, revision 10 – the complete tools component of the SDK.  Download
  • Android SDK Platform-tools, revision 3 – platform tools component of the SDK.  Download
  • Android SDK Platform – our target Android OS.

Android SDK Platform:

STEPS:

  1. Install the JDK using the default setup.
  2. On you Android developer folder (ex. C:\Developers\Android\) place all the zip files you just downloaded.
  3. Create a workspace folder on your home folder (ex. C:\Developers\Android\workspace).
  4. Unzip the Android SDK Starter Package (android-sdk_r10-windows.zip).  NOTE: I suggest to use WinRAR so we can just right-click the zip file and then choose Extract Here
  5. We now have the android-sdk-windows folder on our android developer folder.  Inside this folder, delete the tools folder.  Move the Android SDK Tools (tools_r10-windows.zip) and Android SDK Platform-tools (platform-tools_r03-windows.zip) zip files to this folder.  Unzip them and rename as tools and platform-tools respectively.
  6. Inside android-sdk-windows folder there’s a platforms folder.  Move and unzip the Android SDK Platform file (android-2.3.3_r01-linux.zip) on this folder.
  7. Inside android-sdk-windows folder, create samples folder.  Move and unzip the Android SDK Samples zip file (samples-2.3.3_r01-linux.zip) to this folder.
  8. Unzip the Eclipse file (eclipse-SDK-3.6.1-win32-x86_64.zip).
  9. Inside eclipse folder, run eclipse.exe.  It will ask for the workspace folder to use.  Choose the workspace folder you created.  You can optionally check the Use this as the default and do not ask again checkbox and then click OK.
  10. Still on Eclipse, select Help > Install New Software…. Click Add, in the top-right corner and then click Archive…  Browse and select the downloaded ADT zip file (ADT-10.0.0.zip).  Enter a name for this update site (ex. ADT Plugin) in the Name field and then click OK.
  11. Check the Developer Tools checkbox or click the Select All button and then click Next button and then accept the defaults.  (Sorry, you need to be online as some component need to be downloaded at this part.  I’ll update it once I know how to do the offline mode of it).  After the installation, Eclipse should be restarted.
  12. On Eclipse, select Window > Preferences.  Select Android on the left pane.  On SDK location, browse the select the Android SDK folder (android-sdk-windows) then click Apply.
  13. Still on Eclipse, select Windows > Android SDK and AVD Manager.  Click the Installed Packages on the left pane and you will notice, there’s SDK Platform Android 2.3.3, API 10, revision 1 and Samples for SDK API 10, revision 1.  We are now ready to create virtual devices.
  14. Click Virtual Devices on the left pane.  Click New… button and give the virtual device a name (ex. Gingerbread).  Select Android 2.3.3 API Level 10.  Type 512 or more for SD Card size and then click Create AVD button.  We are now ready to create our famous “Hello World” application.

Referenced by: http://blog.netscribe.us/blog/post/Step-by-Step-Guide-on-How-to-Install-Android-SDK-Offline-%28not-completely-offline%29.aspx

 
99 Comments

Posted by on April 28, 2011 in Android, Mobile Development

 

ActiveMQ via C# using Apache.NMS

ActiveMQ via C# using Apache.NMS Part 1

Java Message Service (JMS) is the de facto standard for asynchronous messaging between loosely coupled, distributed applications. Per the specification, it provides a common way for Java application to create, send, receive and read messages. This is great for enterprises or organizations whose architecture depends upon a single platform (Java), but the reality is that most organizations have hi-bred architectures consisting of Java and .NET (and others). Oftentimes these systems need to communicate using common messaging schematics: ActiveMQ and Apache.NMS satisfy this integration requirement.

JMS Primer
The JMS specification outlines the requirements for system communication between Java Messaging Middleware and the clients that use them. Products that implement the JMS specification do so by developing a provider that supports the set of JMS interfaces and messaging semantics. Examples of JMS providers include open source offerings such as ActiveMQ, HornetQ and GlassFish and proprietary offerings such as SonicMQ and WebSphere MQ. The specification simply makes it easier for third parties to develop providers.

All messaging in JMS is peer-2-peer; clients are either JMS or non JMS applications that send and receive messages via a provider. JMS applications are pure Java based applications whereas non JMS use JMS styled APIs such as ActiveMQ.NMS which uses OpenWire, a cross language wire protocol that allows native access to the ActiveMQ provider.

JMS messaging schematics are defined into two separate domains: queue based and topic based applications. Queue based or more formally, point-to-point (PTP) clients rely on “senders” sending messages to specific queues and “receivers” registering as listeners to the queue. In scenarios where more a queue has more than one listener, the messages are delivered in a round-robin fashion between each listener; only one copy of the message is delivered. Think of this as something like a phone call between you and another person.

Topic based application follow the publish/subscribe metaphor in which (in most cases) a single publisher client publishes a message to a topic and all subscribers to that topic receive a copy. This type of messaging metaphor is often referred to as broadcast messaging because a single client sends messages to all client subscribers. This is some analogous to a TV station broadcasting a television show to you and any other people who wish to “subscribe” to a specific channel.

JMS API Basics
The JMS Standard defines a series of interfaces that client applications and providers use to send messages and receive messages. From a client perspective, this makes learning the various JMS implementations relatively easy, since once you learn one you can apply what you learned to another implementation relatively easily and NMS is no exception. The core components of JMS are as follows: ConnectionFactory, Connection, Destination, Session, MessageProducer, and MessageConsumer. The following diagram illustrates communication and creational aspects of each object:

NMS supplies similar interfaces to the .NET world which allows for clients to send messages to and from the ActiveMQ JMS via OpenWire. A quick rundown of the NMS interfaces are as follows:

Note that the Apache.NMS namespace contains several more interfaces and classes, but these are the essential interfaces that map to the JMS specification. The following diagram illustrates the signature that each interface provides:

The interfaces above are all part of the Apache.NMS 1.30 API available for download here. In order to use NMS in your .NET code you also need to down load the Apache.NMS.ActiveMQ client as well and to test your code, you will need to download and install the ActiveMQ broker, which is written in Java so it requires the JRE to be installed as well. The following table provides links to each download:

For my examples I will be using the latest release of Apache.NMS and Apache.NMS.ActiveMQ as of this writing time. You should simple pick the latest version that is stable. The same applies for ActiveMQ and the JDK/JRE…note that you only need the Java Runtime Environment (JRE) to host install ActiveMQ. Install the JDK if you want to take advantage of some the tools that it offers for working with JMS providers.

To start ActiveMQ, install the JRE (if you do not already have it installed – most people do already) and unzip the ActiveMQ release into a directory…in directory will do. Open a command prompt and navigate to the folder with the ActiveMQ release and locate the “bin” folder, then type ‘activemq”. You should see something like the following:


Download and install the Apache.NMS and Apache.NMS.ActiveMQ libraries from the links defined in the table above. Unzip them into a directory on your hard drive, so that you can reference them from Visual Studio.

Open Visual Studio 2008/2010 and create a new Windows project of type “Class Library”:

And once the project is created, using the “Add Reference” dialog, browse to the directory where you unzipped the Apache.NMS files defined above and a reference to the Apache.NMS.dll. Do the same for the Apache.NMS.ActiveMQ download. Note that each download contains builds for several different .NET versions; I chose the “net-3.5” version of each dll since I am using VS 2008 and targeting the 3.5 version of .NET.

For my examples you will also need to install the latest and greatest version NUnit from http://www.nunit.org. After you have installed NUnit, add a reference to the nunit.framework.dll. Note that any unit testing framework should work.

Add three classes to the project:

  1. A test harness class (ApacheNMSActiveMQTests.cs)
  2. A publisher class (TopicPublisher.cs)
  3. A subscriber class (TopicSubscriber.cs).

Your solution explorer should look something like the following:


The test harness will be used to demonstrate the use of the two other classes. The TopicPublisher class represents a container for a message producer and the TopicSubcriber represents a container for a message consumer.

The Publisher
The publisher, TopicPublisher is a simple container/wrapper class that allows a client to easily send messages to a topic. Remember from my previous discussion about topics that topics allow for broadcast messaging scenarios: a single publisher sends a message to one or more subscribers and that all subscribers will receive a copy of the message.

Message producers typically have a lifetime equal to the amount of time it takes to send a message, however for performance reasons you can extend the life out to the length of the application’s lifetime.

The Subscriber
Like the TopicPublisher above, the TopicSubscriber class is container/wrapper class that allows clients to “listen in” or “subscribe” to a topic.


The TopicSubscriber class is typically has a lifetime that is the equal to the lifetime of the application. The reason is pretty obvious: a publisher always knows when it will publish, but a subscriber never knows when the publisher will send the message. What the subscriber does is create a permanent “listener” to the topic, when a publisher sends a message to the topic, the subscriber will receive and process the message.

Usage Example
The following unit test shows the classes above used in conjunction with the Apache.NMS and Apache.NMS.ActiveMQ API’s to send and receive messages to ActiveMQ which is Java based, from the .NET world!


Here is quick rundown of the ApachNMSActiveMQTests class:

  1. Declare variables for the required NMS objects and the TopicSubscriber
  2. Declare variables for  the broker URI, the topic to subscribe/publish to, and the client and consumer ids
  3. Create a ConnectionFactory object, create and start a Connection, and then create a Session to work with.
  4. Create and start the TopicSubscriber which will be a listener/subscriber to the “TestTopic” topic. Also, to receive messages you must register an event handler or lambda expression with the MessageReceivedDelegate delegate. In this example I in-lined a lambda expression for simplicity.
  5. On the test the method, create a temporary publisher and send a message to the topic.
  6. Tear down and dispose of the subscriber and Session.
  7. Tear down and dispose of the Connection.

After you run the unit test you should see something like the following message:


Note that ActiveMQ must be up and running for the example to work.

 

Referenced by: http://rantdriven.com/post/ActiveMQ-via-C-sharp-and-dotnet-using-ApacheNMS-Part-1.aspx

 

 
Leave a comment

Posted by on April 8, 2011 in C#