Android: Starting a Child Activity from a Parent Activity

by jmorris 29. June 2010 23:07

Despite my early mistakes, starting an Activity to launch a child view off of the main view is pretty simple in Android ;) First define an activity that will act as the parent, in most platforms this is analogous to a "main" method which indicates the starting point for the application and a child Activity that the will be activated from this Activity:

Then create an intent passing in a reference to the current Activity and the class definition of the child Activity. Finally pass the newly created Intent into the startActivity(...) method. Simple ;)

Tags: , , ,

Java | Android

How to fix: "Could not find a base address that matches scheme http for the endpoint with binding WebHttpBinding" Errors

by jmorris 24. June 2010 14:30

After deploying a project from development environment running off of the VS development Web server Cassini to a production box using IIS, I noticed that all of my WCF service were all failing with the same HTTP 500 error:

The problem is that IIS needs to determine which base address in the bindings to host the service. However, WCF services only allows one service hosted under a site to be bound to one base address for a scheme. In situations where you have multiple services being hosted under a single site, the binding must specify a base address to use filter requests to t he specific service.

To resolve the issue, simple provide the base address in the baseAddressPrefixFilters section of the web.config:

By adding the prefix above, only requests with the specified base address above will be passed through. All others will be blocked and a HTTP 500 error returned to the client:

"System.InvalidOperationException: Could not find a base address that matches scheme http for the endpoint with binding WebHttpBinding. Registered base address schemes are []"

Tags: , , , ,

WCF

What is the ObsoleteAttribute Anyway?

by jmorris 22. June 2010 17:31

From time to time during the lifecycle of any API, certain methods or classes simple become obsolete; meaning "No longer useful" or "No longer relevant." Often times it is a warning to users of the API that the lifetime of the said method is "finite" and will or may be removed in the future.  It is also may be an indication that another type or method has been created which supersedes the functionality of the decorated subject.

The FCL even provides a special attribute for flagging methods and types as obsolete: System.ObsoleteAttribute. Here is the MSDN description of the attribute:

“Marks the program elements that are no longer in use. Marking an element as obsolete informs the users that the element will be removed in future versions of the product.


Typically it is added when a method or class must be changed in a way that backward compatibility may not be completely possible. After all, in general most developers try as hard as possible to maintain backwards compatibility; or at least try as hard as their level of comprehension of the API and its clients. Occasionally this isn’t possible, so the attribute is used to flag a clear direction to the developer: “DO NOT USE THIS CLASS, METHOD, ETC…USE CLASS/METHOD/TYPE X, Y, OR Z INSTEAD!!!”

For example, the following method has been flagged with the ObsoleteAttribute and a clear, description directive has been made to all users of the method:


For those that ignore that message and use the method in there code, the compiler will even issue a warning:

So as a plea to all developers, when you encounter the ObsoleteAttribute, please, please respect it and don't use methods or types in your code that are flagged with it Smile

Tags: ,

rant

OOM Exceptions Max Addressable Space and Apache.NMS

by jmorris 15. June 2010 17:30

I kept running into OutOfMemoryExceptions in one my Unit Tests that tested some very basic pub/sub functionality with Apache.NMS. Basically, I could create aproximently 1835 consumers before the following exception was thrown:

I was a bit perplexed by this exception, first all because it happened at nearly the exact same number of consumers being created. Secondly, because that really wasn't that high of a number...I was expected failures to be in 100K or even 1M range...

Looking at my code, the problem became clear as day: I was creating a session per consumer.

Why is this bad? Little background on JMS (Java Messaging Service), which of course Apache.NMS is based (dotnet for JMS):

  • Each client should have a single connection
  • Each connection should manage less than 500 sessions
  • Each session is a thread
  • Each session can create n consumers/subscribers

The problem I was having is that I was running out of addressable space when I was creating 1:1 session to consumer. Each thread took up approximently 1MB thread stack * ~2000 session objects => 2GB max addressable memory space on a windows x86 process. Given that I was running a unit test with Resharper in VS2008, which undoubtedly consumes more threads, I reached the threshold at slightly lower than 2K threads.

With a simple refactor, I was able to run a subsquent unit test where 100K consumers were created on a single session!

Tags: ,

Apache.NMS | JMS

Jeff Morris

Tag cloud

Month List

Page List