Off to TechReady7…

In the following weeks, I'm going to learn about new technologies, strategies – or shorter to say: get a glimpse into the future. I'm going to get tons of information about things like new wave of products and old products' new waves – and what is the worse, I cannot share anything…

So see you in mid-August, when my journey across technology and architecture continues 🙂

Unmanaged resources and leaking

Everybody knows about, that you have to be very keen about using unmanaged resources (like filestreams, sharepoint objects, sockets, etc), disposing them whenever it's important, etc. But do we know all situations, that you have to be careful not to leak memory or not to let an unmanaged resource to be collected by garbage collector (which should mean you were unaware about it being unreleased at the appropiate time)? I tried to collect most of the situations where you may leak an unmanaged object the way you even didn't think about.

Returning a ref value

Wow – returning a value may cause problems? But how? The sad thing – it's not that hard to create a situation when just returning a reference value can cause (curable) problems. Look at this situation:

We have two objects, both of them having unmanaged references to each other – let's name them Parent and Child. Let's state that both of them are backing up unmanaged resources as well. If I return the Child object from a call (let's say Child GetFirstChildForThisParent(guid), and it looks up the parent according to the guid given), the following is happening:

You get a child object, which you use for what reason you would like to use it – the problem arise at the end of your code snippet, when you want to dispose the object – you have to be very cautious when freeing it up. If it has a managed reference to the parent – you can grab it, and free it! Or not? No, you can't dispose it – what happens, if there are anything else in the memory from the parent – any other child, any other references that are hold, etc. So – where are we? Again at the reference counting world of COM arrived? Yes, this can be a solution as well, but what if you create a small class holding the parent and the child object together, and giving that as a result – and of course creating a new parent every time needed… That could work as well. So – this could be a solution, but this will create additional needs on the memory footprint and the number of unmanaged resources…

Iterating over a collection

Ok, what happens, if I iterate over a collecting? Collection iterating is done in two parts – first you get an iterator, than you get the values each by each by calling some property. So – in order not to leak the resources this time, try to reuse the collection from the original object in the iterator, and the main point – plan how you are going to manage the values you are giving from the list. A small problem would arise with this approach – you are not able to modify the collection easily while you are iterating over it, it's not easy anytime, but the unmanaged resources you are holding are going to drive you nuts 🙂

Yielding

Ok, yielding – it's a very good thing, but do we know exactly what is happening? State machine created, calls are stopped by early returns, etc. It's one of the most useful creations in .NET, but – if you followed the previous paragraphs carefully, you already should know what is the problem – you don't have the right control over the creation of unmanaged resources and linkage between them… So, as for the others, you can use this useful tool as well, but you have to be very careful at most of the cases… 🙁

Technorati tags: , , , ,

Open source and … your company?

According to a commenter there is always a question – are we allowed to use non-ms labeled technologies whenever it is appropiate?

Answer is tough – myself had the opportunity to use multiple technologies like NHibernate or NVelocity at multiple projects like a very complex system for a Canadian Insurance Company. And what is 'worse' – I was developer of those open source projects at the cost of my employer.The whole things depends not on technology, but it's inside various brains 🙂

It's all about things like Not Invented Here, Legacy Software, and Big Brand – these are things that cannot be proven by the right technology, just by the right approach. So, sorry, I cannot give the right answer…

Technorati tags:

Open Source Series 2.: NVelocity (part 2)

I forgot an important part of the previous posts – I was talking about many projects using the original Velocity for many purposes – but is the .NET version used? I tried to put together a noncomprehensive list of usages – feel free to comment to add your own! One important thing – currently there are 2 branches on NVelocity – one can be found at http://nvelocity.sf.net, the other is part of Castle – use the latter one, it has more bells and support as well 🙂

This post is part of the open source series

Silverlight and Playready

First of all – the Silverlight DRM client is FREE!

The main component for playing DRM protected content with silverlight streaming was released during the weekend – and it's called PlayReady Server SDK. There are two distinct license agreements depending on your needs – one for developing PlayReady Server Applications (the SDK itself) and another for deploying a PlayReady Service. About the bucks – no, it's not free: for developing applications, 30.000$ one time license fee is needed; for the deployment, an additional 30.000$ processor fee OR a 0.001$/license fee is needed. For qualified customers a 120 days eval period is given as well for testing and evaluating. Another possibility is to license the SDK as an ISV to build WPF applications that could process content protected with PlayReady.
The DRM technology itself is existing since 1999 – and PlayReady technology was later introduced to fullfit the ever increasing need for mobile instrumentation. Silverlight not being a mobile only technology (don't forget – sooner or later it comes to a phone near you, whether it is a Nokia or Smartphone), but thin enough to be a target platform for this technology. In the very soon future the technology will evolve to support literally anything from H.264 to AAC on any PlayReady compatible device and technology.

And now the fun part – how it works?

Silverlight DRM is a small, cross-platform version of the PlayReady client used exclusively by the Silverlight Web browser plug-in. Analogous to other online content services, a Silverlight service that offers protected content uses the PlayReady Server SDK to first encrypt the content. The first time a client tries to playback a protected media comes the individualization feature of the server – it binds the DRM client to the computer it was installed. Client is then authorized to connect to the license server and acquire a license – valid for the duration of the browser session. So every end-user is given an individualized Playready component and different certified license keys. This significantly reduces the danger of global breaks. If a specific version of a PlayReady client becomes compromised, it can be barred from acquiring licenses for new digital media files unless the latest version of the PlayReady client is downloaded that is robust against the circumvention.

If you got interested, you may play around with PlayReady – check the examples site, check the site for licensing, or read about the silverlight client.

Technorati tags: , ,

Open Source Series 2.: NVelocity

Formerly as part of the Apache Jakarta project, now part of the Apache project itself can be found the Velocity project. Since the beginning, it is the de facto tool for generating template driven applications – websites, documents, etc., the list of projects, websites and tools powered by or capable of using Velocity is endless. As for other great and successfull projects (like Hibernate, which also uses velocity for generating POJO files), this was met with the new wind of .NET – there were NVelocity born. So to make it short – NVelocity is a .Net-based template engine – it permits anyone to use the simple yet powerful template language called VTL to reference objects, execute methods, etc defined in .Net code. Speaking of a web application, this leads to the MVC pattern – this simple to use and set up tool enables you to program against modells in your views, and put the controller in charge of binding the two – this (and NHibernate, and ActiveRecord, and Windsor…) is what lead to the born of the Castle and the Rhino projects – but these are in later post :).

So no whistles nor bells, but the main part of NVelocity is:

  • You create the engine – new NVelocity.App.VelocityEngine(ep);
  • You get a template – engine.GetTemplate("template.vm");
  • You create a context – new NVelocity.VelocityContext();
  • You fill the context – context.Put("key", "value");
  • Than you merge the context with the template using the engine – template.Merge(context, outputStream);

The extras are coming mostly in the template file, and by the fact, that there are plenty of way to provide plugins into the system – ResourceLoaders for determining where to get the file (from the filesystem? database? embedded resource?), caches of various parts, etc. So, back to template file – what can I do?

  • I can print the value for a key – ${key}
  • I can use property getters and setters – #set ${object}.prop = "value"
  • I can use loops, if-then-else, define macros, etc
  • Call and return any method with parameterlists which may contain values, arrays, dictionaries, etc – ${object}.Method(${key}, "%{key = 'value', key2 = ${key}}");
  • Meanwhile the whole thing is typesafe and – the template gets compiled into an AST tree the first time it met!

So – I think this is a very handy tool for generating source files, for generating documents and for driving data driven websites.

PS: No, it has nothing to do with Microsoft Velocity – that goes into the cache providers series 🙂

This post is part of the open source series

A short overview of cache providers, part 1

In the following few paragraphs I'll try to a give a less-or-more comprehensive view over the world of cache providers. What we call a cache provider? The first thing people generally do is cache things within their web processes. But this means your cache is duplicated multiple times, once for each thread. This is a waste of memory and you'll get low cache hit rates. If you're using a multi-threaded language or a shared memory API like the built-in System.Web.Cache with in-memory settings, you can have a global cache for all threads, but it's per-machine. It doesn't scale to multiple machines. Once you have 20 webservers, those 20 independent caches start to look just as silly as when you had 20 threads with their own caches on a single box. Cache providers' servers and clients work together to implement one global cache across as many machines as you have – like the state server or sql server options for System.Web.Cache. But is the default implementation of System.Web.Cache flawless and perfect? Some says no – there may be improvement both the server and client sides.

Memcached

Why bother with a linux damon cache implementation made by danga? Answer is easy: first of all – there is a win32 implementation for it. Secondly – there are thons of different APIs to access it from .NET. Three of those APIs am I going to further investigate – the .NET memcached client library, the enyim.com Memcached Client, and BeIT Memcached. (interesting thing to mark – 3 projects, 3 different forge – sourceforge, codeplex and google code 🙂 )

The .NET memcached client library is the one, that mostly follows the schema and technology of the java client – it's a 1:1 port of that one.

The BeIT client comes with many bells and whistles, like socket pooling, uses the ketama algorithm for sticking keys to servers (key – server assigment stays the same even if there are new servers added or removed between), most of the simple value types have their own optimized serialization, have compression schemas, automatic key prefixing, dead server detection, etc.

The enyim.com Memcached client comes with nearly the same set of features, except for an additional one – a provider project to wire it up into System.Web.Cache without any additional steps.

As a special experiment, there are .NET implementations of the memcached server as well, and compared to the native C implementation, they even doesn't work that bad. One of the implementations I tried was part of the experimental hive of the Rhino framework – I'll try to cover that framework in a later post 🙂

33 easy steps to dive into WCF

¾  Step 1 – Read Principles of Service Design: Patterns and Anti-Patterns for an overview of SOA basics (~20 -30 min.)

http://msdn2.microsoft.com/en-us/library/ms954638.aspx

¾  Step 2 – Read Windows Communication Foundation Road Map to get an understanding of WCF goals, and its role in SOA enterprise architecture (~20 -30 min.)

http://msdn2.microsoft.com/en-us/library/aa480211.aspx

¾  Step 3 – Read On the road to Indigo: Prescriptive Guidance for Today's Technologies by Richard Turner to get an understanding of current state of all Microsoft distributed application technologies (20-30 min)

http://blogs.msdn.com/richardt/archive/2004/03/05/84834.aspx 

¾  Step 4 – Read Windows Communication Foundation Architecture Overview by Yasser Shohoud to learn WCF basics: Addresses, Bindings, and Contracts (~45 min.)

http://www.yassers.com/content/soa/WCFArchOverview.aspx

¾  Step 5 – Read Windows Communication Foundation Architecture Overview to learn WCF basics: Endpoints, Bindings, Contracts, Behaviors (~45 min.)

(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnlong/html/wcfarch.asp)

¾  Step 6 – Complete virtual lab “Understanding Windows Communication Foundation” (90 min.)

http://msevents.microsoft.com/CUI/WebCastEventDetails.aspx?EventID=1032315324&EventCategory=3&culture=en-US&CountryCode=US

¾  Step 7 – Complete virtual lab “The Fundamentals of Programming the Windows Communication Foundation Virtual Lab” (90 min.)

http://msevents.microsoft.com/CUI/WebCastEventDetails.aspx?EventID=1032291422&EventCategory=3&culture=en-US&CountryCode=US

¾  Step 8 – Look through WCF latest news and announcements (~20 min.)

http://wcf.netfx3.com/blogs/news_and_announcements/default.aspx

¾  Step 9 – Download and build the Data Contract Samples

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/WCF_Samples_MSDNLive/html/7a6107b5-eda1-491a-94a9-8265ba0c698b.asp

¾  Step 10 – Read the article “Serialization in Windows Communication Foundation”

http://msdn.microsoft.com/msdnmag/issues/06/08/ServiceStation/default.aspx

¾  Step 11 – Read Craig McMurty’s Blog on “Versioning Windows Communication Foundation Services”

http://blogs.msdn.com/craigmcmurtry/archive/2006/07/23/676104.aspx

¾  Step 12 – Read the article and review the code for “Discover Mighty Instance Management Techniques For Developing WCF Apps”

http://msdn.microsoft.com/msdnmag/issues/06/06/WCFEssentials/

http://msdn.microsoft.com/msdnmag/code/?url=http://msdn.microsoft.com/msdnmag/issues/06/06/WCFEssentials/default.aspx (Code)

¾  Step 13 – Read the MSDN Documentation on “Synchronous and Asynchronous Operations”

http://msdn2.microsoft.com/en-us/library/ms734701.aspx

¾  Step 14 – Read Steven M. Cohn’s blogs on “WCF: Asynchronous Operations”

http://weblogs.asp.net/stevencohn/archive/2007/02/05/asynchronous-operations.aspx

http://weblogs.asp.net/stevencohn/archive/2007/03/22/wcf-asynchronous-operations-ii.aspx

¾  Step 15 – Read the MSDN Article “Build a Queued WCF Response Service

http://msdn.microsoft.com/msdnmag/issues/07/02/Foundations/default.aspx

¾  Step 16 – Read Designing and Implementing Services for a high level conceptual orientation to design and implement WCF services.

http://msdn2.microsoft.com/en-us/library/ms729746.aspx

¾  Step 17 – Read Hosting WCF Services

http://www.devx.com/codemag/Article/33655/1954?pf=true

¾  Step 18 – Read WCF Essentials – What You Need To Know About One-Way Calls, Callbacks, And Events by Juval Lowy (Source code included)

http://msdn2.microsoft.com/en-us/library/ms729746.aspx

¾  Step 19 – Read Build a Queued WCF Response Service by Juval Lowy (Source code included) for a brief introduction to WCF queued calls followed by an interesting problem-how to get results out of a queued call-and the solution via some cool WCF programming techniques.

http://msdn.microsoft.com/msdnmag/issues/07/02/Foundations/default.aspx

¾  Step 20 – Review Build a Queued WCF Response Service  on Dr Dobb’s Portal

http://www.ddj.com/dept/windows/196900749

¾  Step 21 – Read the MSDN article on Sessions, Instancing, and Concurrency

http://msdn2.microsoft.com/en-us/library/ms731193.aspx

¾  Step 22 – Read Understanding Windows Communication Foundation Extensibility for an overview of WCF’s extensibility points (~20-30 min.)

http://weblogs.asp.net/andresv/archive/2006/10/19/Understanding-WCF-Extensibility.aspx 

¾  Step 23 – Watch MSDN Architecture Webcast: Extending Windows Communication Foundation by Aaron Skonnard for a demonstration of several key extensibility points (~70 min.)

http://msevents.microsoft.com/cui/WebCastEventDetails.aspx?EventID=1032299314&EventCategory=5

¾  Step 24 – Review the following SDK extensibility samples (~180 min.)

¾  Custom Service Host 
http://msdn2.microsoft.com/en-us/library/aa395224.aspx

¾  Message Inspectors
http://msdn2.microsoft.com/en-us/library/aa717047.aspx

¾  Transport Extensibility Samples   
http://msdn2.microsoft.com/en-us/library/aa967733.aspx

¾  Channels Extensibility Samples
http://msdn2.microsoft.com/en-us/library/aa967568.aspx

¾  Message Encoder Extensibility Samples
http://msdn2.microsoft.com/en-us/library/aa967732.aspx

¾  Instancing Extensibility Samples
http://msdn2.microsoft.com/en-us/library/aa967565.aspx

¾  Step 25 – Review “Administration and Diagnostics” branch in MSDN documentation (~30 min.)

http://msdn2.microsoft.com/en-us/library/ms731055.aspx

¾  Step 26 – Review the following integration and interop scenario guides (~120 min.)

¾  Integrating with COM Applications
http://msdn2.microsoft.com/en-us/library/ms733928.aspx
(especially http://msdn2.microsoft.com/en-us/library/ms730294.aspx)

¾  Integrating with COM+ Applications
http://msdn2.microsoft.com/en-us/library/ms733094.aspx

¾  Integration with .NET Remoting
http://msdn2.microsoft.com/en-us/library/ms730332.aspx

¾  Interoperability with WSE 3.0
http://msdn2.microsoft.com/en-us/library/ms734745.aspx

¾  Interoperability with ASP.NET Web Services
http://msdn2.microsoft.com/en-us/library/ms731779.aspx

¾  Step 27 – Review the following migration related articles (~120 min.)

¾  All About ASMX 2.0, WSE 3.0, and WCF (Aaron Skonnard)
http://msdn.microsoft.com/msdnmag/issues/06/01/servicestation/default.aspx

¾  Anticipating Adopting the Windows Communication Foundation: Easing Future Migration  (From ASP.NET)
http://msdn2.microsoft.com/en-us/library/aa738742.aspx

¾  WCF and ASP.NET Compatibility Mode (Wenlong Dong's Blog)
http://blogs.msdn.com/wenlong/archive/2006/01/23/516041.aspx

¾  Migrating ASP.NET Web Services to WCF
http://msdn2.microsoft.com/en-us/library/ms730214.aspx

¾  Migrating WSE 3.0 Web Services to WCF
http://msdn2.microsoft.com/en-us/library/ms732008.aspx

¾  Step 28 – Read Windows Communication Foundation Transactions Overview to get an understanding of WCF transaction management functionality (~30 min.)

http://msdn2.microsoft.com/en-us/library/ms733904.aspx

Follow up by going through Writing a Transactional Application

http://msdn2.microsoft.com/en-us/library/ms229973(vs.80).aspx

¾  Step 29 – Go through Reliable Messaging demystified blog entry by Shy Cohen (~10 min.)

http://blogs.msdn.com/shycohen/archive/2006/02/20/535717.aspx 

¾  Step 30 – Listen to Secure, Reliable Transacted Messaging with WCF (Part 1)  podcast on Channel 9 (~30 min.)

 http://channel9.msdn.com/Showpost.aspx?postid=173405

¾  Step 31 – Listen to Secure, Reliable Transacted Messaging with WCF (Part 2)  podcast on Channel 9 (~30 min.)

http://channel9.msdn.com/Showpost.aspx?postid=173830

¾  Step 32 – View MSDN TV episode Reliable Messaging in Windows Communication Foundation (~15 min.)

http://msdn.microsoft.com/msdntv/episode.aspx?xml=episodes/en/20050825IndigoSC/manifest.xml

¾  Step 33 – Complete “Reliable and Transacted Messaging with the Windows Communication Foundation Virtual Lab” (~90 min.)

http://msevents.microsoft.com/CUI/WebCastEventDetails.aspx?EventID=1032291421&EventCategory=3&culture=en-US&CountryCode=US

 

Technorati tags: , , ,

Open Source Series 1.: Introduce to the series

In this series (probably) lesser known but very valuable opens source projects will be searched for, found, and most important – write about 🙂

In the following parts I try to cover some of my favourites first, but beside having open eyes I have ears as well – if you know some OS project gems, that are useful, don't hesitate to comment/contact.

Technorati tags: