When we want to develop ThreadSafe solutions .NET two of the options that we can use are Monitor and lock. But what exactly happens when we use one and another? What are the differences between one and the other?
Basically the difference is that lock really emits code that places a a Monitor inside a try...finally block. So the real difference is that lock really gives us a exception proof Monitor, since it makes sure that it gets free of that locking even if an exception occurs.
So lets see a sample of that:
Imagine this as the code that we write using lock.
1: object something = new object();
2: lock (something)
3: {
4: var query = new TargetProcessEntities()
.Bug.Where(bug => bug.BugID > 100);
5:
6: foreach (var bug in query)
7: {
8:
9: Console.WriteLine("{0}", bug.BugID);
10:
11: }
12: }
The generated code will be: (using .NET Reflector)
1: object CS$2$0000;
2: object something = new object();
3: bool <>s__LockTaken0 = false;
4: try
5: {
6: Monitor.Enter(CS$2$0000 = something,
ref <>s__LockTaken0);
7: IQueryable<Bug> query = from bug in
new TargetProcessEntities().Bug
8: where bug.BugID >= 100
9: select bug;
10: foreach (Bug bug in query)
11: {
12: Console.WriteLine("{0}", bug.BugID);
13: }
14: }
15: finally
16: {
17: if (<>s__LockTaken0)
18: {
19: Monitor.Exit(CS$2$0000);
20: }
21: }
So as we can see the lock that we placed in the original code at line 2, really gave place to a try…finally block like we can see at lines 4…6 and 14…21.
Basically when we need to use locks in order to have Thread Safety, than we should use lock instead of Monitor.Enter and Monitor.Exit, since lock really gives us an optimized way to use the Monitor class.
I’d like to thank Richard Blewett for his great explanation of it.
So another session that I did at Microsoft TechDays 2010 Portugal was around Microsoft Entity Framework 4.0 Evolution and features we can expect in the future. And being a 400 Level session I tried to do it as much sample based and interactive as possible, by asking the attendees what were their normal pains when using Entity Framework or any other ORM framework that they were working on, and show a sample of how to do that. Unfortunately there wasn’t as much interaction as I was expecting, but still we could see the most recent evolutions on this technology.
Here’s a summary of what this session was:
- Slight Introduction to Entity Framework and how that is part of the Data Platform Group, and what other elements are also at that group, and those are:
- Visual Studio Integration
- Quadrant
- Entity Framework
- WCF Data Services
- OData
- ADO.NET
- “M” / EDM
- SQL Server
- SQL Azure
- SQL Modeling Services
- …
- New features
- Model-First Development
- We are now able to achieve an approach where we do the EF Model first and after that we generate the database based on that, or only map the Storage Model into it.
- Automatic Pluralization
- The model now has the capability of instead of making the EntitySets named something like the name of the entity and adding Set to the name (ex. Person, PersonSet), we now have the option to pluralize that and it will do that automatically for us (ex. Person, People)
- Foreign Keys in models
- Previously we didn’t had the foreign keys of the navigation properties on our models, now we do.
- POCO Support
- Lazy Loading
- Now lazy loading is on by default and really works without having to use Include like it was previously
- T4 Code Generation
- A complete set of T4 templates we can use and customize to define how we want our code files to be generated
- Template Customization (same as before)
- IObjectSet
- Now we have an interface that is IObjectSet that is the basis of out EntitySet, and what this allows us to do, is create our our POCO classes that are Self-tracking
- Virtual SaveChanges method
- In this version we have SaveChanges marked as virtual, and so we can override that and place our own code in there.
- ObjectStateManager object
- Manages the state of our objects
- Self-tracking Entities
- Capability of doing some entities that are responsible for their own change management, and also aware of those changes
- SQL Generation Improvements
- Huge leap in terms of performance, since a lot was done in order to get the best possible sql code generated based on the Linq query. Examples like the usage of Like clause in SQL when we in Linq use the Contains method, instead of the previously used CharIndex.
- More Linq operator support
- Contains
- DefaultIfEmpty
- Single, SingleOrDefault (in top projection)
- ExecuteStoreQuery and Translate
- Linq Extensibility
- ExecuteStoreQuery
- ExecuteStoreCommand
- Stored Procedures Import improvements
- Capability of having Store Procedures imported to the model as Methods, as well as having also functions as part of the model methods
- Model defined functions (same as above)
- WPF designer integration
- New Designer in VS2010 is done in WPF
- Code-only development (Only at EF Features CTP3)
- Possibility of having all the EF model being done in code without using edmx, csdl, ssdl or msl files. All of this will be described in code.
- Possible Routes using Entity Framework
- Start with the database
- Start with the Model
- Start with .net classes
You can find this presentation here and on SlideShare:
TechDays 2010 Portugal - Entity Framework 4.0 Evolution and Future - 16x9
View more presentations from Nuno.Godinho.
I would enjoy very much to ear your thoughts about this presentation.
It has been a while since I last wrote about my Microsoft TechDays 2010 Portugal sessions, and being really true, it’s been a while since I wrote anything at all, but here I go now of to another start in writing.
So another session that I did at the Portuguese TechDays 2010 event was about Microsoft Silverlight Analytics Framework, and this was done with my friend Ricardo Castelhano. The purpose of this presentation was to give a 360° view of this new Silverlight Framework and what it could mean for our solutions. And as you know Analytics is a very important part of our applications, and I’m not only talking about analytics of page hits, or that sort of things that normally Marketing people want measured, because we need more than that. Imagine if we could understand how our application is working by using this Analytics capabilities, and by doing that we would be instrumenting our application. This was exactly what we talked about.
The summary of this session is the following:
- Design Goals
- Support All the possible usages of Silverlight Applications, and not only when they are on the browser
- Support for multiple analytics services to work simultaneously without impacting the Performance
- Giving Support for Designers to easily use this framework
- Support A/B Testing
- Support for event SketchFlow prototypes
- Support for Silverlight Media Framework
- Architecture
- At this level what happens is that we have 3 (three) elements associated with the way this works, and those are:
- Silverlight Control
- Object that will be analyzed
- Data Collector
- Element that will receive every analysis information and send it to the right Event Log
- Event Log
- Element that will receive and store the analysis information
- Ex. Event Viewer
- How does this work?
- All Silverlight Analytics Framework objects are really Silverlight Behaviors that interact with some specific element
- Extensibility
- There are 3 (three) ways that this framework is being extended, and those are:
- Analysis Services
- This includes the creation of new behaviors
- Several Microsoft Partners and other vendors are doing this for us
- Control Vendors
- Visual Studio Templates
- Templates that are available for Visual Studio in order to ramp-up the new analytical behaviors.
- Partners
- Launch Partners
- Included in the Framework installer
- AT internet
- Comscore
- GlanceGuide
- Google Analytics
- Nedstat
- Preemptive Solutions
- Quandcast
- Supported by Control library
- Additional Committed Partners
- Anvato
- Conviva
- Nielsen
- Skytide
- Visible Measures
- Webtrends
- Unica
- Infragistics
- ShowCase
- Platforms
- Release Information
- Beta Release at MIX10
- Silverlight 3
- Blend 3
- VS2008
- Microsoft Silverlight Media Framework 1.0
- Smooth Streaming Media Element
- SDK RTW
- Silverlight 4
- Blend 4
- VS2010
- Microsoft Silverlight Media Framework 1.0
- Smooth Streaming Media Element
- Availability
- http://msalf.codeplex.com
- Open Source – MS PL
- Community Development
- Beta Status
- Learn from Code
- Microsoft Silverlight Analytics Framework
- Microsoft Silveright Media Framework
- Managed Extensibility Framework
- Framework Installer and Source Code
- http://msaf.codeplex.com
- Free, Open Source (MS-PL) License
- Community Development Including
- Analytics Vendors
- Control Vendors
- Designers
- Developers
- Microsoft Corporation
You can find this presentation here and on SlideShare:
I would enjoy very much to hear your thoughts about this presentation.
During TechDays 2010 in Portugal I did a session about “Event-Driven Architectures: Why, When and How?”. This was a level 300 session and we looked at real situations where we could make use of the EDA Approach. The purpose of this session was to show Why we need another approach other then SOA, and When is EDA a better approach than SO. To finalize we looked at How we can implement EDA, as well the components that this approach uses, and their product mapping.
So the session was based on the following:
- Introduction
- Common Thoughts about SOA and EDA
- SOA is just a Synchronous RPC (mostly over Web Services)
- EDA is SOA
- No. EDA is not SOA. “Event-driven architecture can complement service-oriented architecture (SOA) because services can be activated by triggers fired on incoming events. This paradigm is particularly useful whenever the sink does not provide any self-contained executive” according to Wikipedia.
- The Best of EDA and SOA is combined in SOA 2.0
- That’s right. SOA 2.0 is also known and Event-Driven SOA. “the ability to create high-level business events from numerous low-level system events. Events are created by filtering real-time data (from middleware, applications, databases, and Web services, for example) and infusing it with defining detail such as dependencies or causal relationships discovered by correlating other events.” according to Wikipedia.
- Why do we need this?
- Basically due to a Trend Change that move to a more On-Demand Business, due to:
- The several organization structure changes
- Outsourced processes to External Partners
- Departments and Business Units are now seen as Service Providers
- Loose Coupling of application components
- Example of this is EAI. Ways to achieve this?
- File Transfer
- Problems
- Various non-Standard Formats.
- Translation is needed from one to another format
- Manually Loaded
- Shared Databases
- Problems
- Data is tightly coupled to multiple applications
- Impossible to make incremental or partial updates
- Web Services
- Problems
- Requires services to be available at invocation
- Results in multiple call stacks
- Resource consuming
- Yet another Remote Procedure Call (RPC, COM, Corba, DCOM, ...)
- Messaging
- Benefits
- Defined data format
- Asynchronous Operations
- Minimized Coupling
- Fault Tolerance
- Data Freshness
- Problems
- Almost Impossible to make “reactive” applications
- Events
- Benefits
- Represent a change in state
- Self-Contained
- Uniquely indentified
- Time relevant, not time sensitive
- Sourced using messaging
- Observable
- Event Types
- Execution
- Lifecycle
- Management
- Business
- Event Driven Architecture
- What is EDA?
- Architecture pattern that orchestrates behavior around:
- Production
- Detection
- Consumption of events as well as the responses they invoke.
- Method for building enterprise systems in which events flow between decoupled components and services
- A maintainable, sustainable and extensible model for building complex, distributed applications
- Suited for Asynchronous, unpredictable environments
- Extremely Loosely Coupled
- Inversion of communication
- In contrast to the direct communication frequently used in a composite SOA, or other architectures, communications is done asynchronously through publishing events
- Why do we need EDA?
- Companies must manage and react to a large number events every day in real time
- Real time trade settlement systems
- Flight reservation system
- Streaming stock data
- Real time vehicle location for transportation companies
- Stock Exchange Market systems
- System designers normally must support both events and Services
- Systems must be “Business Oriented”
- Types of EDA?
- Simple Event Processing
- Commonly used to drive the real-time flow of work—taking lag time and cost out of a business
- Event Stream Processing
- Commonly used to drive the real-time flow of information in and around the enterprise, which enables in-time decision making
- Complex Event Processing
- Commonly used to detect and respond to business anomalies, threats, and opportunities.
- Implementation Components
- Event Flow Layers
- Event Generator
- Every event is generated from a source. The source might be an application, data store, service, business process, transmitter, sensor, or collaboration tool (IM, email). An ordinary event may be evaluated for notability by an event preprocessor (router, filter), resulting in the generation of a new notable event.
- Because of the variety of event generators, not all events will be generated in the required format for event processing. In those cases, the events need to be transformed to the required (enterprise standard) format prior to being deposited in the event channel.
- Event Channel
- The event channel, typically a messaging backbone, transports standard formatted events between event generators, event processing engines, and downstream subscribers.
- Event Processing Engine
- In the event processing layer, upon receipt, events are evaluated against event processing rules, and actions are initiated. The event processing rules and actions are defined in accordance to the needs of the interested parties, not of the event generators.
- The actions include invoking a service, initiating a business process, publishing the event out to a subscription hub, directly notifying humans or systems, generating a new event, and/or capturing the event for historical purposes.
- Events are processed by engines. A simple engine processes each event occurrence independently.
- A complex engine processes new event occurrences in context of prior and future events.
- Downstream Activity
- A single event, or event correlation, may initiate numerous downstream activities. The invocation of the activity might be a push by the event processing engine (service invocation, business process initiation, notification) or a pull by subscribers of event publications.
- Subscribers might be humans, applications, active business processes, data warehouses, performance dashboards, and/or automated agents.
- Events should be published in the standard event format. Transformation to subscriber-specific formats is typically done by an enterprise integration backbone.
- SOA vs EDA
- SOA
- Applications are composed in design-time
- Linear flow between services
- Predictable behavior
- Request/Response is common, and often overused
- EDA
- Applications are composed at run-time
- Asynchronous components
- Reactive behavior
- What do SOA applies to?
- Vertical interaction between the hierarchical layers of functional decomposition
- Functional request-and-reply processes such as man-machine dialogues; the user waits for an answer
- Processes with a transactional nature which require commit and rollback facilities
- Data enrichment in a message to be published to bring the message to its full content in a formal format
- What do EDA applies to?
- Horizontal communication between tiers in a process chain
- Workflow type of processes
- Processes that cross recognizable functional organization borders, external (B2B) as well as internal
- Conclusion
- There’s no SOA vs EDA, they really work very well together and complete one another
- How to Implement
- Using Web service technologies today, and additional SOAP-aware message queuing infrastructure.
- Current ESB infrastructures provide a way of message queuing combined with Web service technologies.
- SOA and EDA implementations must be regarded in the context of Business Process Management (BPM)
- Modern BPM-tools are based on BPEL (Business Process Execution Language)
- Current BPEL implementation focuses strongly on the command-and-control model, the orchestration of services, and so on SOA
- Beside orchestration BPEL - to a certain extend - also supports workflow, a kind of choreography, which goes in the direction of EDA
- BPEL has a procedural nature
- EDA would rather be a declarative model.
- Preparation Steps:
- 1. Model business requirements into functions at the granularity level of the desired autonomy.
- 2. Outline the application landscape to identify all affected systems.
- 3. Map the application landscape to the business function model.
- 4. Identify applications that cross functional borders as potential "agility bottlenecks" (assign a special high priority to those applications that are required to cross external organization borders).
- Basics for the decoupled service boundaries
- Resources
- Books
- Enterprise Integration Patterns (Gregor Hohpe and Bobby Woolf)
- Patterns for Enterprise Architecture (Martin Fowler)
- SOA Patterns (Arnon Rotem-Gal-Oz, Eric Bruno, Udi Dahan)
- Event Processing: Designing IT Systems for Agile Companies (K. Chandy , W. Schulte)
- Event-Driven Architecture: How SOA Enables the Real-Time Enterprise (Hugh Taylor, Angela Yochem, Les Phillips, Frank Martinez)
- SOA Design Patterns (The Prentice Hall Service-Oriented Computing Series from Thomas Erl)
- Sites
You can find this presentation here and on SlideShare:
I would enjoy very much to ear your thoughts about this presentation.
During TechDays 2010 in Portugal I did a session about “Introduction to Silverlight 4.0”, that was really a level 200 session, which means that we were doing a lot of Intro to the New features of Silverlight 4.0, and having a clear insight about what we can do, and who is currently using it and with which results.
So the session was based on the following:
- Introduction to Silverlight
- Here we talked a little bit about the history of Silverlight, in terms of what it can do, where it works, how it works, and how it is growing.
- Customer Stories
- Media
- Some Silverlight Media Stories were presented like:
- nbcsports.msnbc.com (NFL Sunday Night Football)
- Roland Garros 2009 Tennis Tournment
- NBCOlympics
- NetFlix
- For Portuguese examples we saw:
- Business Applications
- Some LOB Stories
- For Portuguese examples we talked about:
- RIA
- Some RIA Stories
- For Portuguese examples we saw:
- Digital Marketing
- Some Digital Marketing Stories
- For Portuguese examples we saw:
- Silverlight 4.0 specific features
- Analysis in the following areas
- Media
- Rich Experiences
- Business Applications
- Beyond the Browser
- Developer Tools
You can find this presentation here and on SlideShare:
I would enjoy very much to ear your thoughts about this presentation.
So in TechDays 2010 Portugal I did a session about “Workflow Services and Windows Server AppFabric – How they work great together”. Basically this session was sliced in the following parts:
- Introduction
- What are the Workflow Services?
- What is Windows Server AppFabric?
- How to achieve Coordination Of Work
- How to achieve Message Correlation
- How to do Monitoring with Windows Server AppFabric
- How to do Persistence with Windows Server AppFabric
- In terms of Farm Availability, How does AppFabric helps
So these were the several topics of my presentation that can be found here.
So TechDays 2010 Portugal already ended and it was a very interesting 3 day Event. In terms of Contents I would say that it was one of the best I’ve ever been, and so I think that tells it all.
In this years event I did several talks, in several different areas of expertise and I got some very positive feedback and also some very helpful feedback, that I’ll take into account in my next presentations.
So in order to maintain the Sessions running, even though the event already ended I’ll post my materials here and would like to ear more comments from you, as well as answer all your questions, and do some more deep dive into the session contents and also the areas we talked about.
So here’s a list of my TechDays 2010 Portugal talks:
- “Workflow Services and Windows Server AppFabric – How they work great together”
- “Scale your Data-tier with Windows Server AppFabric Caching”
- “Event Driven Architecture: When, Why and How?”
- “Introduction to Silverlight 4.0”
- “Microsoft Silverlight Analytics Framework”
- “WCF RIA Services – Deep-Dive”
- “Entity Framework 4.0 and Beyond”
I hope you find this several Sessions interesting.
Josh Holmes – UX Evangelist @ Microsoft
Twitter: @JoshHolmes
In-House or Hosted Servers
- In House
- Barrier for Innovation
- Requires a large amount of IT that needs to be bought and needs a lot of money and also takes a lot of time
- “Waste” of capacity
- Our businesses have spikes but that’s not the normal usage, but in order to permit that usage we need to have that IT capacity and so we waste a lot of that capacity
- Cloud Computing
- No Initial costs, and this the investment needed
- Cloud Computing is not competing with Shared Hosting, this is for real enterprise applications
Types of Cloud
- Private Cloud (On-Premise)
- Infrastructure (IaaS)
- We manage only a small amount of the Infrastructure and not all the network
- Platform as a Service (PaaS)
- We don’t manage any infrastructure but only take advantage of the platform services that are being released
- Windows Azure seats here
Windows Azure Data Centers (~100 Globally Distributed Data Centers)
- US
- Quincy, WA
- Chicago, IL
- San Antonio, TX
- …
- Europe
- Asia
Microsoft CDN – Content Delivery Network . Currently in CTP
The Microsoft Cloud
- Application Services
- Bing
- Windows Live
- Office Live
- Health Vault
- Microsoft Advertising
- Software Services
- Office Online
- Dynamics CRM Online
- Exchange Online
- …
- Platform Services
- Windows Azure
- SQL Azure
- AppFabric
- Live Mesh
- …
Not everything has to or can live in the cloud.
Only need the things that benefits on being in the cloud.
The core Strategy is ‘Hybrid’, we call that Software + Services
Where is the cloud most compelling
- Massive scales: Outback promo on Facebook
- High reliability: eCommerce Apps
- Variable load
Reasons to use the cloud
- Improve Bottom Line Business
- Improve Strategy
Windows Azure VMs
- Small
- 1 x 1.8GHz
- 1.76 GB memory
- Medium
- 2 x 1.8 GHz
- 3.5 GB memory
- Large
- X-Largeb
Determine an ROI
Windows Azure Roles
- Web Role
- External Facing
- Http/Https endpoints
- Short lived calls
- “Think Web Server”
- Worker Role
- Internal Facing
- TCP/HTTP endpoint
- Long running processes
- “Think Service or Deamon”
Running PHP and Ruby on Azure
- We can place the all the php files inside the package and have several versions of PHP running in different WebRoles
- How to do it
- Host in WebRole (like in .NET)
- Package the PHP runtime
- Point to FastCGI
Windows Azure for Eclipse
- Does a lot of the heavy lifting for you
- Creates the Web.config, Web.roleConfig, PHP implementation and debugs in the dev fabric
- http://windowsazure4e.org
Running EXEs in Worker Role
- Start with Worker Role Process to
- Copy the exes to the worker role’s app directory
- Execute the process
- Monitor the health of the process
- Other auxiliary tasks
- Examples:
- Deploying Tomcat on Windows Azure
- Deploying MySQL
- …
Storage Options
- Windows Azure Storage
- Types Available:
- Queues
- Buffered delivery data storage
- Blobs
- Unstructured data Storage
- Partitioned by Containers
- Tables
- Semi-structured or tabular a storage (not the same as SQL Tables)
- Tables contain entities
- Entities contain properties
- Tables are contained in partitions
- Partitions are the units of replication
- Support ACID transitions
- Loosely typed
- Non Relational DB
- Massive scalable
- Drives
- SDKs
- SQL Azure
- Relational Data storage
- Fully structured
- Strongly typed
- RDMS
- Highly Scalable
- guaranteed 99.999 % uptime
- 3 replicas are guaranteed
- Not Supported
- Physical Server Access
- Catalog DDL
- CLR
- Service Broker
- Reporting Services
- Analysis Services
- Distributed Transactions and Queries
- Supported
- Tables, Indexes, Views
- Stored procedures
- Triggers
- constraints
- table variables
- temp tables
- Database Migration
Admin Windows Azure Data Storage
- http://windows.azure.com and make some Storage type project
- This gives you access to a storage account and also the AccountName and ApplicationId that you’ll need to develop against it
MySQL in a Windows Azure Application
- Running MySQL in a Worker Role
Zend Framework has now support for Windows Azure for Azure Storage, and will have support for Azure AppFabric (Service Bus, Access Control)
Today we had a small “leak” from an unknown source from Microsoft, about TechDays 2010 in Portugal stating that you can already register for techdays 2010 at www.techdays2010.com.
Don’t forget to go there and start now to register for this incredible event for both Developers and IT Pros.
Every once and a while I go to CodePlex and try to look at some interesting projects that exist in there and this time I was looking for Silverlight related projects, and this was what I’ve found:
Hope this helps you.
More Posts
Next page »