A lot of people these days write short tit-bits on social networking sites instead of paragraphs and journals of hand-written notes. I think it's an evolution of the Orkut scrapbook and the Facebook wall - you would now post messages to your own scrapbook/wall and people following your mini-blog get notified, often via a free SMS text message.
When you let visitors add comments to your posts, you would reply back to their comment and there's no way for them to know that you've replied to their comment. Blogger.com addresses that by emailing you all comments after yours (or at least that's what I think it does) if you check a little box when posting a comment.
Some systems are smarter and maintain a tree-like structure to keep track of which post is a reply to which other post, but then it all depends on how the designers intended it to be. Being an architect myself, I have to make trade-offs between cost and functionality and, in the end, the more you spend, the better stuff you can come up with.
Saturday, October 27, 2007
Friday, October 26, 2007
Java Application as a Windows Service
I was looking up some way to turn a Java application into a Windows service.
In Linux/Unix, it's much simpler since all you need to do is specify a command with all arguments, which in our case is the JVM executable java.exe with the class or Java archive name as a parameter.
In Windows, we would use a product like the Java Service Wrapper or the Java Service Launcher to launch the application whenever Windows starts up, without requiring the user to log in.
I haven't tried either of those products yet since I'm not currently into Java development, but when I do I'll post more about them here.
In Linux/Unix, it's much simpler since all you need to do is specify a command with all arguments, which in our case is the JVM executable java.exe with the class or Java archive name as a parameter.
In Windows, we would use a product like the Java Service Wrapper or the Java Service Launcher to launch the application whenever Windows starts up, without requiring the user to log in.
I haven't tried either of those products yet since I'm not currently into Java development, but when I do I'll post more about them here.
Monday, October 22, 2007
.NET Remoting over TCP
Remoting in .NET is quite similar to RMI in Java. To begin with, we need an object that has the methods we would be executing on the server-side. This object inherits from MarshalByRefObject. This indicates that the client does not get a copy of the object but rather a reference to the remote object. We then have a hosting process and a client process.
In our example, the hosting process creates a new instance of the TcpChannel class (pass the TCP port number to the constructor of TcpChannel for the server hosting process) and registers the object using ChannelServices.RegisterChannel. Then, the class we are hosting has to be registered using the RemotingConfiguration.RegisterWellKnownServiceType method - it takes the type of our class as the first parameter, the registration name as the second parameter and the object mode (singleton & single call modes) as the third parameter. When creating a console application, we would usually add a Console.ReadLine statement at the end of the application to prevent it from exiting.
The client application would create and register an instance of TcpChannel. Then, obtain an instance of the class hosted on the server using Activator.GetObject - with the type of the class as the first parameter and the URL (Example: tcp://localhost:8080/my_service) as the second parameter. You can now call methods on the object as you would for a normal object.
In our example, the hosting process creates a new instance of the TcpChannel class (pass the TCP port number to the constructor of TcpChannel for the server hosting process) and registers the object using ChannelServices.RegisterChannel. Then, the class we are hosting has to be registered using the RemotingConfiguration.RegisterWellKnownServiceType method - it takes the type of our class as the first parameter, the registration name as the second parameter and the object mode (singleton & single call modes) as the third parameter. When creating a console application, we would usually add a Console.ReadLine statement at the end of the application to prevent it from exiting.
The client application would create and register an instance of TcpChannel. Then, obtain an instance of the class hosted on the server using Activator.GetObject - with the type of the class as the first parameter and the URL (Example: tcp://localhost:8080/my_service) as the second parameter. You can now call methods on the object as you would for a normal object.
Sunday, October 21, 2007
Type Forwarding
Type Forwarding enables client applications to refer to a library at compile time for a type that is later moved to another library.
Example:
using System.Runtime.CompilerServices;
[assembly:TypeForwardedTo(typeof(DestinationLib.TheType))]
Example:
using System.Runtime.CompilerServices;
[assembly:TypeForwardedTo(typeof(DestinationLib.TheType))]
The IFormattable interface
Implementing the IFormattable interface let's you do much more with the ToString() method if you're developing text-based applications or are trying to create strings out of object fields.
To implement the IFormattable interface, you have to create a ToString method that accepts a format string and an IFormatProvider object. The IFormatProvider object isn't relevant but the format string can be used, such as to return only one field of an object. Here's a sample implementation:
class TimeInterval : IFormattable {
...
public override string ToString() {
return ToString(null, null);
}
public string ToString (string format, IFormatProvider formatProvider) {
if (format == null) {
return this.Hour.ToString() + ":" + this.Minute.ToString();
} else if (format == "h") {
return this.Hour.ToString();
} else if (format == "m") {
return this.Minute.ToString();
} else throw new Exception("Invalid format specified");
}
}
To use the new method, you could provide a format string to either string.Format or Console.WriteLine. Example:
TimeInterval timeInterval = new TimeInterval();
Console.WriteLine("{0:h} hours and {0:m} minutes", timeInterval);
Console.WriteLine("{0,2:h}:{0,2:m}", timeInterval); //the ",2" specifies the minimum number of characters in the resulting string - if positive, the output is left-padded, otherwise it is right-padded
To implement the IFormattable interface, you have to create a ToString method that accepts a format string and an IFormatProvider object. The IFormatProvider object isn't relevant but the format string can be used, such as to return only one field of an object. Here's a sample implementation:
class TimeInterval : IFormattable {
...
public override string ToString() {
return ToString(null, null);
}
public string ToString (string format, IFormatProvider formatProvider) {
if (format == null) {
return this.Hour.ToString() + ":" + this.Minute.ToString();
} else if (format == "h") {
return this.Hour.ToString();
} else if (format == "m") {
return this.Minute.ToString();
} else throw new Exception("Invalid format specified");
}
}
To use the new method, you could provide a format string to either string.Format or Console.WriteLine. Example:
TimeInterval timeInterval = new TimeInterval();
Console.WriteLine("{0:h} hours and {0:m} minutes", timeInterval);
Console.WriteLine("{0,2:h}:{0,2:m}", timeInterval); //the ",2" specifies the minimum number of characters in the resulting string - if positive, the output is left-padded, otherwise it is right-padded
Saturday, October 20, 2007
Common Interfaces
The following are some common interfaces implemented by user-defined types:
IComparable: This is required for sorting.
IDisposable: This is used for manually disposing an object
IConvertible: This provides conversion to a base type
ICloneable: This is to provide a copy for an object
IEquatable: This is used when comparison of objects using "==" is required
IFormattable: This is used to convert an object into a formatted string (rather than use the base ToString method)
IComparable: This is required for sorting.
IDisposable: This is used for manually disposing an object
IConvertible: This provides conversion to a base type
ICloneable: This is to provide a copy for an object
IEquatable: This is used when comparison of objects using "==" is required
IFormattable: This is used to convert an object into a formatted string (rather than use the base ToString method)
Group chat coming soon in GoogleTalk
Google has a GoogleTalk gadget web client accessible from it's website at http://www.google.com/talk . It features Group chat but the downside is that it doesn't receive offline messages. As a friend from the old country would say, you've got to pick what suits the moment.
If it's any indicate of what's to come, we should see Group Chat in the GoogleTalk client sometime soon.
If it's any indicate of what's to come, we should see Group Chat in the GoogleTalk client sometime soon.
Subscribe to:
Posts (Atom)