Microsoft Robotics
Concurrency and Coordination Runtime (CCR) is a managed code library, a Dynamically Linked Library (DLL), accessible from any language targeting the .NET Common Language Runtime (CLR).
The CCR addresses the need of service-oriented applications to manage asynchronous operations, deal with concurrency, exploit parallel hardware and deal with partial failure. It enables the user to design applications so that the software modules or components can be loosely coupled; meaning they can be developed independently and make minimal assumptions about their runtime environment and other components. This approach changes how the user can think of programs from the start of the design process and deals with concurrency, failure and isolation in a consistent way.
Problem Areas
Asynchrony - When communicating between loosely coupled software components, like programs running across the network, or User Interface (UI) code communicating with the user input and the file I/O subsystem, asynchronous operations enable the code to scale better, be more responsive, and deal with failure across multiple operations. Asynchronous programming however, considerably reduces the readability of user code, since logic is often split between callbacks and the code that originates the operation. In addition, it is an almost impossible task to correctly handle failure across multiple outstanding operations.
Concurrency - Code that needs to better utilize multiple execution resources, must be split into independent logical segments, that can run in parallel, and communicate when necessary to produce results from the combined execution. Often, that logical segment is captured by the thread OS primitive, that is nothing more than a long lived iteration. Because of thread performance implications on thread startup, the thread stays active for long periods of time. This forces a particular pattern. Code is structured as long sequences that use blocking or synchronous calls, and only deals with one thing at a time. Further, threads assume that the primary communication between them is shared memory, forcing the programmer to use very explicit, error-prone methods to synchronize access to that shared memory.
Coordination and Failure Handling - Coordinating between components is where most of the complexity in large software programs lies. A mismatch of interaction patterns, such as calling methods on objects versus using OS signaling primitives versus using queues plus signaling, leads to unreadable code, where the runtime behavior changes drastically between coordination approaches. More importantly, the error handling approaches are ill-defined and again vary drastically.
Application Model
CCR is appropriate for an application model that separates components into pieces that can interact only through messages. Components in this model need means to coordinate between messages, deal with complex failure scenarios, and effectively deal with asynchronous programming. This application model is also very similar to how heterogeneous hardware is integrated and how network applications are built. Most software programs have the same needs, from traditional client PC programs to server applications, to applets running in the Web browser. The software needs to coordinate user input, storage input/output and UI presentation. Although disguised in layers of mostly synchronous application code interfaces, asynchrony is inevitable since the devices operate at different speeds, have large differences in resources available, and we in general know how to use queues to isolate them.
The following sections introduce the CCR programming model and its implementation that addresses the above areas in an efficient, robust and extensible way.
© 2010 Microsoft Corporation. All Rights Reserved.
Friday, December 17, 2010
Array of Tuples
Q: How would use tuples in C# 4.0 to create an array of tuples containing various types of data (i.e. Employee Name, Employee ID#)?
A: Listed below is a sample code snippet to implement an array of tuples.
//Array of Tuples (i.e. EmpName, EmpIDNum)
Tuple[] EmpRecs =
{
Tuple.Create("Sam Nasr", 891),
Tuple.Create("Jim Smith", 358),
Tuple.Create("Lisa Jones", 962)
};
string FirstEmpName = EmpRecs[0].Item1;
string SecondEmpName = EmpRecs[1].Item1;
int SecondEmpIDNum = EmpRecs[1].Item2;
More information can be found at http://msdn.microsoft.com/en-us/library/dd413854(VS.95).aspx
A: Listed below is a sample code snippet to implement an array of tuples.
//Array of Tuples (i.e. EmpName, EmpIDNum)
Tuple[] EmpRecs =
{
Tuple.Create("Sam Nasr", 891),
Tuple.Create("Jim Smith", 358),
Tuple.Create("Lisa Jones", 962)
};
string FirstEmpName = EmpRecs[0].Item1;
string SecondEmpName = EmpRecs[1].Item1;
int SecondEmpIDNum = EmpRecs[1].Item2;
More information can be found at http://msdn.microsoft.com/en-us/library/dd413854(VS.95).aspx
NTLM Authentication for Java http clients
I was working to provide NTLM authentication to a RSS aggregator plugin http://confluence.atlassian.com/display/CONFEXT/RSS+aggregator+macro+plugin , in our implementation the rssaggregator needed to access rss feed from an IIS installed application within an AD intergrated setup, so our http request needed to go through NTLM authentication.
What I found out during this exercise is that if one is on the same AD domain as the server hosting the secure contents then JDK 1.5 and 1.6 does a transparent authentication at the backend, automatically transferring the login details from the http client to the server , however if the request is being made from a client outside the domain then the login details have to be provided using the username and password for the client accessing the protected resource, for that I found the Jave Authenticator class to be the best option, since you do not have to alter your existing code and just call the Authenticator before the http request and populate the authentication credentials in it. Worked really well for me.
References
Two exhaustive definitions of how ntlm works, and the interactions
http://www.innovation.ch/personal/ronald/ntlm.html
http://davenport.sourceforge.net/ntlm.html
Useful link to valid Java Implementation
http://oaklandsoftware.com/papers/ntlm.html
Ads by Google
What I found out during this exercise is that if one is on the same AD domain as the server hosting the secure contents then JDK 1.5 and 1.6 does a transparent authentication at the backend, automatically transferring the login details from the http client to the server , however if the request is being made from a client outside the domain then the login details have to be provided using the username and password for the client accessing the protected resource, for that I found the Jave Authenticator class to be the best option, since you do not have to alter your existing code and just call the Authenticator before the http request and populate the authentication credentials in it. Worked really well for me.
References
Two exhaustive definitions of how ntlm works, and the interactions
http://www.innovation.ch/personal/ronald/ntlm.html
http://davenport.sourceforge.net/ntlm.html
Useful link to valid Java Implementation
http://oaklandsoftware.com/papers/ntlm.html
Ads by Google
Oh Yahoo!
Yahoo has hit rock bottom. They’ve now, finally, had their layoffs. Those that are left are keeping their resumes fresh don’t expect to stay there over the long term. Everything we hear from employees boils down to this – the company is in “absolute disarray.”
Take yesterday as an example. They botch news about closing down products like Delicious. The Upcoming team is apparently wiped out, but an apparently timestamped blog post appeared on wednesday, after the team was gone, asking for feedback on a new design for the site. Except the blog post doesn’t have a link to the new design, and still doesn’t as of today. Probably because whoever wrote it is gone, along with the rest of the team.
And today Yahoo realized that people really care about sites like Delicious and put up a blog post saying that they’re going to sell it, not shut it down. Which is great except the Delicious blog is now offline and returns an error (we reprinted it here).
And finally, yesterday Yahoo announced internally that they would be shutting down an instant messaging product called MyM. Have you heard of it? Neither had we. Oh wait, we did – in 2008. It turns out is was an internal project that was never launched and formally shut down nearly three years ago. Apparently the executive team didn’t know that.
In May I spoke with CEO Carol Bartz on stage at TechCrunch Disrupt. The headline was the last few seconds of the talk. But that wasn’t really what was interesting about the interview. What really riled Yahoo up was when I asked if they were really even a technology company any more. I think it’s now clear to the world now that they aren’t. They’re just a nightmarish Dilbert-cartoon version of the old Yahoo, where employees fear for their jobs and stumble around the office trying to protect themselves, not build anything new and ambitious.
There is only one way a company recovers from this. They must have new leadership. And soon. Because at this point they are little more than a holding company for some lucrative Asian Internet assets. This can’t possibly be what the board of directors hoped for when they hired Bartz less than a year ago. So much has changed, so fast.
Take yesterday as an example. They botch news about closing down products like Delicious. The Upcoming team is apparently wiped out, but an apparently timestamped blog post appeared on wednesday, after the team was gone, asking for feedback on a new design for the site. Except the blog post doesn’t have a link to the new design, and still doesn’t as of today. Probably because whoever wrote it is gone, along with the rest of the team.
And today Yahoo realized that people really care about sites like Delicious and put up a blog post saying that they’re going to sell it, not shut it down. Which is great except the Delicious blog is now offline and returns an error (we reprinted it here).
And finally, yesterday Yahoo announced internally that they would be shutting down an instant messaging product called MyM. Have you heard of it? Neither had we. Oh wait, we did – in 2008. It turns out is was an internal project that was never launched and formally shut down nearly three years ago. Apparently the executive team didn’t know that.
In May I spoke with CEO Carol Bartz on stage at TechCrunch Disrupt. The headline was the last few seconds of the talk. But that wasn’t really what was interesting about the interview. What really riled Yahoo up was when I asked if they were really even a technology company any more. I think it’s now clear to the world now that they aren’t. They’re just a nightmarish Dilbert-cartoon version of the old Yahoo, where employees fear for their jobs and stumble around the office trying to protect themselves, not build anything new and ambitious.
There is only one way a company recovers from this. They must have new leadership. And soon. Because at this point they are little more than a holding company for some lucrative Asian Internet assets. This can’t possibly be what the board of directors hoped for when they hired Bartz less than a year ago. So much has changed, so fast.
Tuesday, December 14, 2010
Zombie Farm
A few days ago Apple released its top 10 list of iPhone apps for 2010 and only one freemium app was listed as top grossing, Zombie Farm. Zombie Farm combines all the fun of Farmville with zombies (!), allowing you to plant either crops or corpses (seriously). You can then use the zombies you’ve planted to attack your neighbors or pirates or aliens (no, I am not making this up).
Apparently this is a winning combination, as the game hit 7.3 million downloads in November, up from 6 million in October and growing about 25% a month. Currently it boasts about 2 million monthly active users, a number which has been doubling every couple of months since the app’s launch this February. Users have spent 2.76 billion minutes playing the game, which have resulted in 61.5 million Zombie Farm invasions. And despite complaints about the most recent updates’ slowness in the iTunes reviews, the developers are obviously doing something right.
To the tune of millions of dollars. Playforge developer Vince McDonnell and his wife were in danger of losing their house when he built the app, and now not so much. While McDonnell will not reveal how much total revenue the app has made thus far (people pay for in-game currency like $0.99 brains and tombstones) in comparison, Doodle Jump, the #10 app on the top grossing list sold about 3 million units in five months at $0.99 each which would project to about ($) 7 million sold for the year. Zombie Farm was at number #6 on the list, which means McDonnell has made at least a few million thus far.
Apparently this is a winning combination, as the game hit 7.3 million downloads in November, up from 6 million in October and growing about 25% a month. Currently it boasts about 2 million monthly active users, a number which has been doubling every couple of months since the app’s launch this February. Users have spent 2.76 billion minutes playing the game, which have resulted in 61.5 million Zombie Farm invasions. And despite complaints about the most recent updates’ slowness in the iTunes reviews, the developers are obviously doing something right.
To the tune of millions of dollars. Playforge developer Vince McDonnell and his wife were in danger of losing their house when he built the app, and now not so much. While McDonnell will not reveal how much total revenue the app has made thus far (people pay for in-game currency like $0.99 brains and tombstones) in comparison, Doodle Jump, the #10 app on the top grossing list sold about 3 million units in five months at $0.99 each which would project to about ($) 7 million sold for the year. Zombie Farm was at number #6 on the list, which means McDonnell has made at least a few million thus far.
Monday, February 8, 2010
GWT games
Many years ago I wrote javascript application that took an image, broke it up into many pieces, then shuffled them into a puzzle for the user. It only worked in I.E. and was horribly written and hard to maintain.
I wanted to revisit this application and was trying to figure out what the best language/framework to use.
I decided that GWT (Google Web Toolkit) would be an excellent choice for this application.
To see the application go here: http://imageoverflow.appspot.com/puzzle.html?imageUrl=http://imageoverflow.appspot.com/get/3b20793dfc300d058ad04d411da152eb?f=t
Now to the code...
The code consists of the following main classes.
ImagePuzzleWidget
PuzzleGrid
ClickableImage
ImagePuzzleWidget
The ImagePuzzleWidget is the main widget that encapsulates the game. It takes no arguments and is added directly to the Root Panel in the GWT entry point.
public void onModuleLoad() {
RootPanel.get().add(new ImagePuzzleWidget());
}
PuzzleGrid
PuzzleGrid extends the Grid GWT component. Its constructor looks like this:
public PuzzleGrid(final String url,final int cols,final int rows)
This class takes the url of the image you want to scramble as well as how many rows and cols you want.
We add an onLoadHandler that will get executed after the image has been loaded:
image.addLoadHandler(new LoadHandler() {
public void onLoad(LoadEvent event) {
setWidth(image.getWidth() + "px");
setHeight(image.getHeight() + "px");
int blockWidth = image.getWidth() / cols;
int blockHeight = image.getHeight() / rows;
for (int col = 0; col <>
for (int row = 0; row <>
setWidget(row, col,
new ClickableImage(url, blockWidth * col, blockHeight * row, blockWidth, blockHeight, row, col));
}
}
shuffle();
setVisible(true);
}
});
It is this class that does most of the work by splitting the image into sub parts and making ClickableImages out of them.
The class then shuffles the images and sets it as visible.
So now we have an image displayed broken into sub parts and displayed in a grid fashion.
ClickableImage
ClickableImage class, as its name implies embodies a section of the image that can be clicked.
The class basically just extends Image and adds a ClickHandler. I add some extra convenience methods like select and unselect which I won't show for the sake of brevity.
public ClickableImage(String url, int left, int top, int width, int height, int row, int col) {
super(url, left, top, width, height);
this.row = row;
this.col = col;
this.addStyleName("unselected");
this.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
toggleSelected();
}
});
}
And that is really all there is to it. By using GWT we can focus on writing our OO style code and not worry about the browser.
Make sure you check out the app at: http://imageoverflow.appspot.com/puzzle.html?imageUrl=http://imageoverflow.appspot.com/get/3b20793dfc300d058ad04d411da152eb?f=t
This post was written hastily, if there is any interest or question leave a comment and I'll ake the time to expand.
HTH
I wanted to revisit this application and was trying to figure out what the best language/framework to use.
I decided that GWT (Google Web Toolkit) would be an excellent choice for this application.
To see the application go here: http://imageoverflow.appspot.com/puzzle.html?imageUrl=http://imageoverflow.appspot.com/get/3b20793dfc300d058ad04d411da152eb?f=t
Now to the code...
The code consists of the following main classes.
ImagePuzzleWidget
PuzzleGrid
ClickableImage
ImagePuzzleWidget
The ImagePuzzleWidget is the main widget that encapsulates the game. It takes no arguments and is added directly to the Root Panel in the GWT entry point.
public void onModuleLoad() {
RootPanel.get().add(new ImagePuzzleWidget());
}
PuzzleGrid
PuzzleGrid extends the Grid GWT component. Its constructor looks like this:
public PuzzleGrid(final String url,final int cols,final int rows)
This class takes the url of the image you want to scramble as well as how many rows and cols you want.
We add an onLoadHandler that will get executed after the image has been loaded:
image.addLoadHandler(new LoadHandler() {
public void onLoad(LoadEvent event) {
setWidth(image.getWidth() + "px");
setHeight(image.getHeight() + "px");
int blockWidth = image.getWidth() / cols;
int blockHeight = image.getHeight() / rows;
for (int col = 0; col <>
for (int row = 0; row <>
setWidget(row, col,
new ClickableImage(url, blockWidth * col, blockHeight * row, blockWidth, blockHeight, row, col));
}
}
shuffle();
setVisible(true);
}
});
It is this class that does most of the work by splitting the image into sub parts and making ClickableImages out of them.
The class then shuffles the images and sets it as visible.
So now we have an image displayed broken into sub parts and displayed in a grid fashion.
ClickableImage
ClickableImage class, as its name implies embodies a section of the image that can be clicked.
The class basically just extends Image and adds a ClickHandler. I add some extra convenience methods like select and unselect which I won't show for the sake of brevity.
public ClickableImage(String url, int left, int top, int width, int height, int row, int col) {
super(url, left, top, width, height);
this.row = row;
this.col = col;
this.addStyleName("unselected");
this.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
toggleSelected();
}
});
}
And that is really all there is to it. By using GWT we can focus on writing our OO style code and not worry about the browser.
Make sure you check out the app at: http://imageoverflow.appspot.com/puzzle.html?imageUrl=http://imageoverflow.appspot.com/get/3b20793dfc300d058ad04d411da152eb?f=t
This post was written hastily, if there is any interest or question leave a comment and I'll ake the time to expand.
HTH
Monday, October 5, 2009
Extend JSF Command Link
I found myself adding a Remove link throughout my JSF application. It looked like this:
<h:commandlink value="Remove" actionlistener="#{MyBean.remove}">
I wanted to add a confirm dialog. So I added this.
<h:commandlink value="Remove" actionlistener="#{MyBean.remove}" onclick="javascript return confirm('Are you sure')">
But as I copied and pasted this through 5 or 6 different pages, I got to thinking, there has to be a better way.
So I created a custom jsf component by extending Command Link.
Step 1
First step was to create my new tag. It simply wraps the default command link.
package com.acme;
import com.sun.faces.taglib.html_basic.CommandLinkTag;
import javax.el.MethodExpression;
import javax.el.ValueExpression;
import javax.faces.component.UIComponent;
import javax.faces.component.html.HtmlCommandLink;
import javax.faces.event.MethodExpressionActionListener;
import javax.faces.webapp.UIComponentELTag;
/**
* @author cmcintosh
*/
public class RemoveCommandLinkTag extends UIComponentELTag { // Declare a bean property for the hellomsg attribute.
CommandLinkTag commandLink = new CommandLinkTag();
ValueExpression value;
MethodExpression actionListener;
// Associate the renderer and component type.
public String getComponentType() {
return commandLink.getComponentType();
}
public String getRendererType() {
return commandLink.getRendererType();
}
@Override
protected void setProperties(UIComponent component) {
super.setProperties(component);
component.setValueExpression("value", value);
((HtmlCommandLink)component).addActionListener(new MethodExpressionActionListener(actionListener));
((HtmlCommandLink)component).setOnclick("javascript:return confirm('Are you sure you want to remove?')");
}
@Override
public void release() {
super.release();
commandLink.release();
}
public void setValue(ValueExpression value) {
this.value = value;
}
public void setActionListener(MethodExpression actionListener) {
this.actionListener = actionListener;
}
}
Step 2
Next I needed to create a tld.
<taglib version="2.0" xmlns="http://java.sun.com/xml/ns/j2ee" xsi="http://www.w3.org/2001/XMLSchema-instance" schemalocation="http://java.sun.com/xml/ns/j2ee web-jsptaglibrary_2_0.xsd">
<tlib-version>1.0</tlib-version>
<short-name>datastore</short-name>
<uri>/WEB-INF/tlds/datastore</uri>
<tag>
<name>RemoveCommandLink</name>
<tag-class>com.acme.datastore.web.components.tags.RemoveCommandLinkTag</tag-class>
<attribute>
<name>value</name>
<deferred-value>
<type>java.lang.String</type>
</deferred-value>
</attribute>
<attribute>
<name>actionListener</name>
<required>false</required>
<deferred-method>
<method-signature>
actionListener(javax.faces.event.ActionEvent)
</method-signature>
</deferred-method>
<type>String</type>
</attribute>
</tag>
</taglib>
This was one of the hardest parts note the deferred-method and deferredvalue. I've never encountered those before.
Step 3
Add it to the web.xml:
<jsp-config>
<taglib>
<taglib-uri>http://datastore.acme.com/datastore</taglib-uri>
<taglib-location>/WEB-INF/tlds/datastore.tld</taglib-location>
</taglib>
</jsp-config>
Step 4
Finally to use it:
<%@taglib prefix="ds" uri="http://datastore.acme.com/datastore"%>
.
.
.
<ds:removecommandlink value="Remove" actionlistener="#{ViewModifyTable.removeColumn}">
<f:param name="applicationId" value="#{ViewModifyTable.applicationId}">
<f:param name="tableName" value="#{ViewModifyTable.tableName}">
</f:param></f:param></ds:removecommandlink></h:commandlink></h:commandlink>
<h:commandlink value="Remove" actionlistener="#{MyBean.remove}">
I wanted to add a confirm dialog. So I added this.
<h:commandlink value="Remove" actionlistener="#{MyBean.remove}" onclick="javascript return confirm('Are you sure')">
But as I copied and pasted this through 5 or 6 different pages, I got to thinking, there has to be a better way.
So I created a custom jsf component by extending Command Link.
Step 1
First step was to create my new tag. It simply wraps the default command link.
package com.acme;
import com.sun.faces.taglib.html_basic.CommandLinkTag;
import javax.el.MethodExpression;
import javax.el.ValueExpression;
import javax.faces.component.UIComponent;
import javax.faces.component.html.HtmlCommandLink;
import javax.faces.event.MethodExpressionActionListener;
import javax.faces.webapp.UIComponentELTag;
/**
* @author cmcintosh
*/
public class RemoveCommandLinkTag extends UIComponentELTag { // Declare a bean property for the hellomsg attribute.
CommandLinkTag commandLink = new CommandLinkTag();
ValueExpression value;
MethodExpression actionListener;
// Associate the renderer and component type.
public String getComponentType() {
return commandLink.getComponentType();
}
public String getRendererType() {
return commandLink.getRendererType();
}
@Override
protected void setProperties(UIComponent component) {
super.setProperties(component);
component.setValueExpression("value", value);
((HtmlCommandLink)component).addActionListener(new MethodExpressionActionListener(actionListener));
((HtmlCommandLink)component).setOnclick("javascript:return confirm('Are you sure you want to remove?')");
}
@Override
public void release() {
super.release();
commandLink.release();
}
public void setValue(ValueExpression value) {
this.value = value;
}
public void setActionListener(MethodExpression actionListener) {
this.actionListener = actionListener;
}
}
Step 2
Next I needed to create a tld.
<taglib version="2.0" xmlns="http://java.sun.com/xml/ns/j2ee" xsi="http://www.w3.org/2001/XMLSchema-instance" schemalocation="http://java.sun.com/xml/ns/j2ee web-jsptaglibrary_2_0.xsd">
<tlib-version>1.0</tlib-version>
<short-name>datastore</short-name>
<uri>/WEB-INF/tlds/datastore</uri>
<tag>
<name>RemoveCommandLink</name>
<tag-class>com.acme.datastore.web.components.tags.RemoveCommandLinkTag</tag-class>
<attribute>
<name>value</name>
<deferred-value>
<type>java.lang.String</type>
</deferred-value>
</attribute>
<attribute>
<name>actionListener</name>
<required>false</required>
<deferred-method>
<method-signature>
actionListener(javax.faces.event.ActionEvent)
</method-signature>
</deferred-method>
<type>String</type>
</attribute>
</tag>
</taglib>
This was one of the hardest parts note the deferred-method and deferredvalue. I've never encountered those before.
Step 3
Add it to the web.xml:
<jsp-config>
<taglib>
<taglib-uri>http://datastore.acme.com/datastore</taglib-uri>
<taglib-location>/WEB-INF/tlds/datastore.tld</taglib-location>
</taglib>
</jsp-config>
Step 4
Finally to use it:
<%@taglib prefix="ds" uri="http://datastore.acme.com/datastore"%>
.
.
.
<ds:removecommandlink value="Remove" actionlistener="#{ViewModifyTable.removeColumn}">
<f:param name="applicationId" value="#{ViewModifyTable.applicationId}">
<f:param name="tableName" value="#{ViewModifyTable.tableName}">
</f:param></f:param></ds:removecommandlink></h:commandlink></h:commandlink>
Subscribe to:
Posts (Atom)