<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Clay Lenhart's Blog</title>
	<atom:link href="http://clay.lenharts.net/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://clay.lenharts.net/blog</link>
	<description>A blog on .Net and SQL Server</description>
	<lastBuildDate>Tue, 31 Oct 2017 10:34:08 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=4.2.2</generator>
	<item>
		<title>SQL Server Compressed Backup Bugfix Release</title>
		<link>http://clay.lenharts.net/blog/2011/07/30/sql-server-compressed-backup-bugfix-release/</link>
		<comments>http://clay.lenharts.net/blog/2011/07/30/sql-server-compressed-backup-bugfix-release/#comments</comments>
		<pubDate>Sat, 30 Jul 2011 00:38:06 +0000</pubDate>
		<dc:creator><![CDATA[Clay Lenhart]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://clay.lenharts.net/blog/?p=165</guid>
		<description><![CDATA[Bugfix 1.2-20110729 increases a timeout when estimating the size of a differential backup. Previous releases could fail with a timeout error if the database was large.]]></description>
				<content:encoded><![CDATA[<p>Bugfix 1.2-20110729 increases a timeout when estimating the size of a differential backup.  Previous releases could fail with a timeout error if the database was large.</p>
]]></content:encoded>
			<wfw:commentRss>http://clay.lenharts.net/blog/2011/07/30/sql-server-compressed-backup-bugfix-release/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>WebSockets is cool, but what can you do today?</title>
		<link>http://clay.lenharts.net/blog/2010/10/19/websockets-is-cool-but-what-can-you-do-today/</link>
		<comments>http://clay.lenharts.net/blog/2010/10/19/websockets-is-cool-but-what-can-you-do-today/#comments</comments>
		<pubDate>Tue, 19 Oct 2010 19:05:48 +0000</pubDate>
		<dc:creator><![CDATA[Clay Lenhart]]></dc:creator>
				<category><![CDATA[ASP.Net]]></category>
		<category><![CDATA[Ajax]]></category>
		<category><![CDATA[ASP.Net MVC]]></category>
		<category><![CDATA[Comet]]></category>
		<category><![CDATA[Web Application]]></category>
		<category><![CDATA[WebSockets]]></category>

		<guid isPermaLink="false">http://clay.lenharts.net/blog/?p=136</guid>
		<description><![CDATA[WebSockets is a new feature that appears to be a great way to send messages from the server to the browser, however today there isn't much support, both in browsers and on the server in IIS and ASP.Net.  

Today you can use a Comet technique (in particular, Ajax with long polling) which is available in all browsers.  Using this concept, the browser makes a standard AJAX call to the server that waits until it receives a message.  Asynchronous Pages and Asynchronous Controller allow you to have long running HTTP requests without using precious ASP.Net threads. <a href="http://clay.lenharts.net/blog/2010/10/19/websockets-is-cool-but-what-can-you-do-today/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>WebSockets is a new feature that appears to be a great way to send messages from the server to the browser, however today there isn&#8217;t much support, both in browsers and on the server in IIS and ASP.Net.  </p>
<p>Today you can use a <a href="http://en.wikipedia.org/wiki/Comet_%28programming%29">Comet technique</a> (in particular, <a href="http://en.wikipedia.org/wiki/Comet_%28programming%29#Ajax_with_long_polling">Ajax with long polling</a>) which is available in all browsers.  Using this concept, the browser makes a standard AJAX call to the server that waits until it receives a message. Asynchronous Pages and Asynchronous Controller allow you to have long running HTTP requests without using precious ASP.Net threads.<br />
<span id="more-136"></span></p>
<p>On the server, there are two resource limits to consider with IIS and ASP.Net:</p>
<ul>
<li>HTTP request limits &#8212; in IIS7 the default limit is 5000</li>
<li>ASP.Net thread limits &#8212; in IIS7 the default limit is 12 x number of CPUs </li>
</ul>
<p>For a typical ASP.Net application (and ASP.Net MVC application), an HTTP request always uses an ASP.Net thread.  However you can use <a href="http://msdn.microsoft.com/en-us/magazine/cc163725.aspx">Asynchronous Pages in ASP.Net</a> or <a href="http://msdn.microsoft.com/en-us/library/ee728598.aspx">Asyncronous Controllers in ASP.Net MVC</a> to free the ASP.Net thread (but still keep the HTTP request). Using Asynchronous Pages or Controllers is ideal for Comet HTTP requests.</p>
<p>Take for example an email web application that has jQuery code to check for new mail.  It calls /CheckEmail which returns either true or false. As soon as it completes it calls checkEmail() immediately so that it can be notified of any new mail.</p>
<pre class="brush: jscript; title: ; notranslate">
        $(function () {
            checkEmail();
        });

        function checkEmail() {
            $.post(&quot;/CheckEmail&quot;, null, function (data, s) {
                if (data.d) {
                    $('#emailCheck').text('You have mail!');
                } else {
                    $('#emailCheck').text('No change.');
                }

                checkEmail();
            });
        }
</pre>
<p>On the server, the code uses the AsyncController to free the ASP.Net thread for other HTTP requests until this HTTP request has completed.</p>
<pre class="brush: csharp; title: ; notranslate">
    public class CheckEmailController : AsyncController
    {
        //
        // GET: /CheckEmail/

        public void IndexAsync()
        {
            AsyncManager.OutstandingOperations.Increment();
            MyAsyncEmailChecker.CheckForEmailAsync(hasEmail =&gt;
            {
                AsyncManager.Parameters[&quot;hasEmail&quot;] = hasEmail;
                AsyncManager.OutstandingOperations.Decrement();
            });
        }

        private class IndexResponse
        {
            public bool d { get; set; }
        }

        public JsonResult IndexCompleted(bool hasEmail)
        {
            return this.Json(new IndexResponse() { d = hasEmail });
        }

    }
</pre>
<p>There are three phases on the server. </p>
<pre class="brush: csharp; title: ; notranslate">
        public void IndexAsync()
        {
            AsyncManager.OutstandingOperations.Increment();
            MyAsyncEmailChecker.CheckForEmailAsync(/* callback function */);
        }
</pre>
<p>The first phase calls AsyncManager.OutstandingOperations.Increment() and MyAsyncEmailChecker.CheckForEmailAsync.  When AsyncManager.OutstandingOperations is zero, the matching &#8220;Completed&#8221; method is called. This increment prevents the Completed method from being called before the data is ready. Next the code initiates an Async call to MyAsyncEmailChecker.CheckForEmailAsync().  This is a method I wrote, and in fact it just a demo class for this article.  It returns immediately and then calls the callback function 5 seconds later. &#8220;Async&#8221; functions are common in the .Net framework, for example:</p>
<ul>
<li><a href="http://msdn.microsoft.com/en-us/library/k0syd8kf.aspx">MessageQueue.BeginReceive</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/aa719796%28VS.71%29.aspx">Asynchronous Webservice calls</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/system.net.sockets.socket.beginsend.aspx">Socket.BeginSend</a></li>
</ul>
<pre class="brush: csharp; title: ; notranslate">
            /* an Async function */(hasEmail =&gt;
            {
                AsyncManager.Parameters[&quot;hasEmail&quot;] = hasEmail;
                AsyncManager.OutstandingOperations.Decrement();
            })
</pre>
<p>The next phase calls the function passed in when the MyAsyncEmailChecker finishes. It sets the return data in the AsyncManager.Parameters collection.  These are the same parameters found in the IndexCompleted method.  Next the code calls AsyncManager.OutstandingOperations.Decrement().  Now that AsyncManager.OutstandingOperations is zero, ASP.Net MVC will call IndexCompleted().</p>
<pre class="brush: csharp; title: ; notranslate">
        public JsonResult IndexCompleted(bool hasEmail)
        {
            return this.Json(new IndexResponse() { d = hasEmail });
        }
</pre>
<p>The IndexCompleted method returns the data to the browser &#8212; in this case it is a JsonResult.</p>
<p>Lastly, most browsers limit 2 HTTP connections to the same server, though recent browsers do not have this limitation.  If the browser has a long running HTTP connection to recent messages from the server, it is using one of your two HTTP connections.</p>
<p>UPDATE 2011-05-20: You can download the full source code <a href="http://clay.lenharts.net/blog/wp-content/uploads/MvcAsyncTest.zip">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://clay.lenharts.net/blog/2010/10/19/websockets-is-cool-but-what-can-you-do-today/feed/</wfw:commentRss>
		<slash:comments>97</slash:comments>
		</item>
		<item>
		<title>SQL Server Compressed Backup v1.2 Released</title>
		<link>http://clay.lenharts.net/blog/2009/11/23/sql-server-compressed-backup-v12-released/</link>
		<comments>http://clay.lenharts.net/blog/2009/11/23/sql-server-compressed-backup-v12-released/#comments</comments>
		<pubDate>Mon, 23 Nov 2009 14:44:22 +0000</pubDate>
		<dc:creator><![CDATA[Clay Lenhart]]></dc:creator>
				<category><![CDATA[MSSQL Compressed Backup]]></category>
		<category><![CDATA[SQL Server Administration]]></category>

		<guid isPermaLink="false">http://clay.lenharts.net/blog/?p=126</guid>
		<description><![CDATA[I've just released version 1.2-20091123 of SQL Server Compressed Backup.  SQL Server Compressed Backup will back up a SQL Server database to a compressed file, using either gzip, zip and bzip2.  The new features are: <a href="http://clay.lenharts.net/blog/2009/11/23/sql-server-compressed-backup-v12-released/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>I&#8217;ve just released version 1.2-20091123 of <a href="https://sourceforge.net/projects/mssqlcompressed/">SQL Server Compressed Backup</a> which can be <a href="https://sourceforge.net/projects/mssqlcompressed/files/MSSQLCompressedBackup/1.2-20091123/MSSQLCompressedBackup-1.2-20091123.zip/download">downloaded here</a>.  </p>
<p>SQL Server Compressed Backup will back up SQL Server databases using either gzip, zip or bzip2 compression.</p>
<p>The new features are:<br />
<span id="more-126"></span></p>
<ul>
<li>Fixed the encoding problem by removing “\s”, “\p” and “\\” since they are commonly used in file paths and replacing them with “;;” to mean “;”. Looking at the command line options, it is only necessary to encode the semicolon, so “;;” is the only encoding the command line does.</li>
<li>Added a feature I’ve personally wanted: progress updates and an estimated time until completion. It is more verbose at the beginning (every few seconds), then slows down. After an hour of backing up, updates are only once every 24 minutes.</li>
<li>Worked on the BlockSize and BufferCount request. I’m not keen on implementing BlockSize. I’d like to hear someone explain how they take advantage of it. My understanding is that BlockSize is only for writing to devices (tapes and CD-ROMs — not files on a CD-ROM though), so it doesn’t seem appropriate for backing up to files. BufferCount and MaxTransferSize seem like reasonable options to request, so these are now available.</li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://clay.lenharts.net/blog/2009/11/23/sql-server-compressed-backup-v12-released/feed/</wfw:commentRss>
		<slash:comments>129</slash:comments>
		</item>
		<item>
		<title>How SSAS Cube Processing Affects Running Queries</title>
		<link>http://clay.lenharts.net/blog/2009/05/29/how-ssas-cube-processing-affects-running-queries/</link>
		<comments>http://clay.lenharts.net/blog/2009/05/29/how-ssas-cube-processing-affects-running-queries/#comments</comments>
		<pubDate>Fri, 29 May 2009 19:26:55 +0000</pubDate>
		<dc:creator><![CDATA[Clay Lenhart]]></dc:creator>
				<category><![CDATA[SSAS]]></category>
		<category><![CDATA[cube processing]]></category>

		<guid isPermaLink="false">http://clay.lenharts.net/blog/?p=119</guid>
		<description><![CDATA[SSAS cube processing can kill running queries.  That's right, it may kill queries in order to commit changes to the cube.  

Here is what happens during SSAS cube processing. <a href="http://clay.lenharts.net/blog/2009/05/29/how-ssas-cube-processing-affects-running-queries/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>SSAS cube processing can kill running queries.  That&#8217;s right, it may kill queries in order to commit changes to the cube.  </p>
<p>Here is what happens during SSAS cube processing.<span id="more-119"></span></p>
<ol>
<li>The cube finishes calculating the next version of the cube</li>
<li>Before the data can be made available, SSAS prevents new queries from running</li>
<li>Any currently running queries are allowed to finished normally for 30 seconds</li>
<li>After 30 seconds, SSAS kills any running queries</li>
<li>SSAS commits the new version and allows new queries to hit the updated data</li>
</ol>
<p>The 30 second time out is a configuration setting that you can read about <a href="http://geekswithblogs.net/darrengosbell/archive/2007/04/24/SSAS-Processing-ForceCommitTimeout-and-quotthe-operation-has-been-cancelledquot.aspx">here</a>.</p>
<p>So, that&#8217;s right, SSAS may kill long running queries.</p>
]]></content:encoded>
			<wfw:commentRss>http://clay.lenharts.net/blog/2009/05/29/how-ssas-cube-processing-affects-running-queries/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>Execution Plan of Frequent Queries</title>
		<link>http://clay.lenharts.net/blog/2009/05/29/execution-plan-of-frequent-queries/</link>
		<comments>http://clay.lenharts.net/blog/2009/05/29/execution-plan-of-frequent-queries/#comments</comments>
		<pubDate>Fri, 29 May 2009 19:03:42 +0000</pubDate>
		<dc:creator><![CDATA[Clay Lenhart]]></dc:creator>
				<category><![CDATA[SQL Server Administration]]></category>
		<category><![CDATA[dynamic management views]]></category>
		<category><![CDATA[execution plan]]></category>
		<category><![CDATA[SQL Server 2005]]></category>
		<category><![CDATA[SQL Server 2008]]></category>
		<category><![CDATA[SQL Server Engine]]></category>

		<guid isPermaLink="false">http://clay.lenharts.net/blog/?p=110</guid>
		<description><![CDATA[Bill Galashan, DBA of bet365 sent over the following query that lists the execution plan of the 10 most frequently executed queries. <a href="http://clay.lenharts.net/blog/2009/05/29/execution-plan-of-frequent-queries/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>Bill Galashan, DBA of <a href="http://www.bet365.com/">bet365</a> sent over the following query that lists the execution plan of the 10 most frequently executed queries.</p>
<p>He writes:</p>
<blockquote><p>We got into this due to different query plans coming from a VB or a web app than what was seen when running the same query from Management Studio. Eventually tracked this down to a difference in the set options predominatley whether Arithabort was on or off. </p></blockquote>
<p>Read more to see his query.<span id="more-110"></span></p>
<p>Click here to <a href="http://clay.lenharts.net/blog/2008/04/13/cached-execution-plans-in-sql-server/">see the execution plan of currently running queries</a>. </p>
<pre class="brush: sql; title: ; notranslate">
SELECT TOP 10 creation_time, last_execution_time,  last_worker_time / 1000 as [Last Worker Time (ms)] ,min_worker_time / 1000 as [Min Worker Time (ms)], 
      max_worker_time / 1000 as [Max Worker Time (ms)],
    total_worker_time/execution_count/1000 AS [Avg Worker Time (ms)],
    execution_count, 
    SUBSTRING(st.text, (qs.statement_start_offset/2) + 1,
    ((CASE statement_end_offset 
        WHEN -1 THEN DATALENGTH(st.text)
        ELSE qs.statement_end_offset 
        END 
            - qs.statement_start_offset)/2) + 1) as statement_text,plan_generation_num ,query_plan, Plan_handle
FROM sys.dm_exec_query_stats as qs
CROSS APPLY sys.dm_exec_sql_text(qs.sql_handle) as st
CROSS APPLY sys.dm_exec_query_plan(qs.plan_handle)
-- where st.text like '%proc name to be searched for%'
ORDER BY execution_count DESC;
</pre>
<pre class="brush: sql; title: ; notranslate">
--- Determine options used at run time

select  * from sys.syscacheobjects with (nolock) where sql like '%proc to be searched for%' and objtype='proc'


select dbo.fn_setopts(249)

/*
 This contains a bitmap containing the SET options relevant to each cached plan for a proc.
The following function can be used to decipher this bitmask:
*/

 

create function dbo.fn_setopts(@setopts int)
returns nvarchar(4000)

as
begin

declare @s nvarchar(4000)
select @s='Options: '
if @setopts &amp;amp;amp;amp;amp; 1    &gt; 0 select @s = @s + N'ANSI_PADDING, ' 
if @setopts &amp;amp;amp;amp;amp; 2    &gt; 0 select @s = @s + N'max degree of parallelism, '
if @setopts &amp;amp;amp;amp;amp; 4    &gt; 0 select @s = @s + N'FORCEPLAN, ' 
if @setopts &amp;amp;amp;amp;amp; 8    &gt; 0 select @s = @s + N'CONCAT_NULL_YIELDS_NULL, '
if @setopts &amp;amp;amp;amp;amp; 16   &gt; 0 select @s = @s + N'ANSI_WARNINGS, '
if @setopts &amp;amp;amp;amp;amp; 32   &gt; 0 select @s = @s + N'ANSI_NULLS, '
if @setopts &amp;amp;amp;amp;amp; 64   &gt; 0 select @s = @s + N'QUOTED_IDENTIFIER, '
if @setopts &amp;amp;amp;amp;amp; 128  &gt; 0 select @s = @s + N'ANSI_NULL_DFLT_ON, '
if @setopts &amp;amp;amp;amp;amp; 256  &gt; 0 select @s = @s + N'ANSI_NULL_DFLT_OFF, '
if @setopts &amp;amp;amp;amp;amp; 512  &gt; 0 select @s = @s + N'NO_BROWSETABLE, '
if @setopts &amp;amp;amp;amp;amp; 1024 &gt; 0 select @s = @s + N'TriggerOneRow, '
if @setopts &amp;amp;amp;amp;amp; 2048 &gt; 0 select @s = @s + N'ResyncQuery, '
if @setopts &amp;amp;amp;amp;amp; 4096 &gt; 0 select @s = @s + N'ARITHABORT, '
if @setopts &amp;amp;amp;amp;amp; 8192 &gt; 0 select @s = @s + N'NUMERIC_ROUNDABORT, ' 

return @s

end
</pre>
]]></content:encoded>
			<wfw:commentRss>http://clay.lenharts.net/blog/2009/05/29/execution-plan-of-frequent-queries/feed/</wfw:commentRss>
		<slash:comments>28</slash:comments>
		</item>
		<item>
		<title>GWT is Flexible &#8212; an iPhone Demo</title>
		<link>http://clay.lenharts.net/blog/2009/05/25/gwt-is-flexible-iphone-demo/</link>
		<comments>http://clay.lenharts.net/blog/2009/05/25/gwt-is-flexible-iphone-demo/#comments</comments>
		<pubDate>Mon, 25 May 2009 14:36:30 +0000</pubDate>
		<dc:creator><![CDATA[Clay Lenhart]]></dc:creator>
				<category><![CDATA[Languages]]></category>
		<category><![CDATA[GWT]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Web Application]]></category>

		<guid isPermaLink="false">http://clay.lenharts.net/blog/?p=57</guid>
		<description><![CDATA[GWT is a very flexible environment that allows you to write a web application in Java and compile it to Javascript -- even for the iPhone.  A number of people have fears with GWT, for instance GWT isn't flexible which will lead developers down a dead-end path and GWT is ugly, and can't be used to make "gucci" UIs. This post will show that these are just myths. <a href="http://clay.lenharts.net/blog/2009/05/25/gwt-is-flexible-iphone-demo/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>GWT is a very flexible environment that allows you to write a web application in Java and compile it to Javascript &#8212; even for the iPhone.</p>
<p>A number of people have fears with GWT, for instance </p>
<ul>
<li>(not true) GWT isn&#8217;t flexible which will lead developers down a dead-end path.</li>
<li>(not true) GWT is ugly, and can&#8217;t be used to make &#8220;gucci&#8221; UIs.</li>
</ul>
<p>This post will show that these are just myths.<span id="more-57"></span></p>
<div><strong>Demos</strong></div>
<p>First, lets take a look at the demo.  Below is a re-write of Apple&#8217;s &#8220;Simple Browser&#8221; demo using GWT.  You can find the original demo here: <a href="https://developer.apple.com/webapps/docs/referencelibrary/index-date.html">https://developer.apple.com/webapps/docs/referencelibrary/index-date.html</a> (search on the page for &#8220;simple browser&#8221;).</p>
<p>You can try the GWT version of the demo on the iPhone: <a title="live demo of the GWT version" href="http://clay.lenharts.net/blog/wp-content/images/20090525/Sampleiphoneapp/Sampleiphoneapp.html" target="_blank">live GWT demo</a>, and the <a href="http://clay.lenharts.net/blog/wp-content/images/20090525/sampleiphoneapp.zip">source code</a> which includes the source control history.</p>
<p>or compare it to the <a title="The original Apple demo of &quot;Simple Browser&quot;" href="http://clay.lenharts.net/blog/wp-content/images/20090525/SimpleBrowser/" target="_blank">original Apple demo</a></p>
<p>For those who don&#8217;t have an iPhone, here is a quick video of the demo written in GWT:</p>
<p><object width="560" height="340" data="http://www.youtube.com/v/RZwR6tynsms&amp;hl=en&amp;fs=1" type="application/x-shockwave-flash"><param name="allowFullScreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.youtube.com/v/RZwR6tynsms&amp;hl=en&amp;fs=1" /><param name="allowfullscreen" value="true" /></object></p>
<p><strong>GWT is Flexible</strong></p>
<p>The iPhone provides several unique challenges to GWT:</p>
<ul>
<li>iPhone has specific events like orientation change, touch, and transition end events</li>
<li>iPhone has specific animation features to slide from one &#8220;page&#8221; to the next (Page, in the demo, is conceptual.  Once the app is loaded, it never goes to another HTML page.)</li>
<li>The built-in GWT controls prefer tags like &lt;div> and &lt;table>.  We want to use other HTML tags such as &lt;ul&gt; and &lt;li&gt; in the iPhone</li>
</ul>
<p>GWT manages events, with good reason.  By managing events, <a href="http://code.google.com/p/google-web-toolkit/wiki/DomEventsAndMemoryLeaks">GWT prevents a whole class of memory leaks</a>.  So implementing events that GWT is unaware of is not ideal.  The demo handles this by either firing event on objects that will always exist in the application, or adding or remove events when the control is added or removed from the DOM using the onLoad() and onUnload() methods.</p>
<p>The GWT demo wires up the iPhone specific events by calling native JSNI method.  In native methods you write any Javascript you want, but you have the added risk of memory leaks.  This method wires up the screen orientation change event:</p>
<pre class="brush: java; title: ; notranslate">
	private native void registerOrientationChangedHandler(
			OrientationChangedDomEvent handler) /*-{
		var callback = function(){
			handler.@net.lenharts.gwt.sampleiphoneapp.client.model.Screen$OrientationChangedDomEvent::onOrientationChanged()();
		}

		$wnd.addEventListener(&quot;orientationchange&quot;, callback, false);
	}-*/;
</pre>
<p>When the screen orientation changes, the handler.@net.lenharts.gwt.sampleiphoneapp.client.model.Screen$OrientationChangedDomEvent::onOrientationChanged()() method is called, which is a special GWT notation allow you to call Java methods from Javascript.  When the code is compiled to Javascript, this will be replaced with the actual compiled Javascript function.</p>
<p>Animations on the iPhone are surprising easy.  In fact <a href="http://webkit.org/blog/138/css-animation/">animations are included in the CSS 3 specification</a> soon to be released.  If you have the Google Chrome 2 browser, you can try out the animations in the link.</p>
<p>To use these animations the pseudo code is </p>
<ol>
<li>Set the content of a element.</li>
<li>Set the element to a CSS class that disables animations</li>
<li>Set the element to another CSS class that will position the element at the beginning position of the animation (give the element two classes)</li>
<li>Schedule a <a href="http://google-web-toolkit.googlecode.com/svn/javadoc/1.5/com/google/gwt/user/client/DeferredCommand.html">DeferredCommand</a></li>
<li>In the DeferredCommand, remove the CSS classes set above and set the element to a CSS class that enables animations.</li>
<li>Then set the element to a CSS class to position the element at the destination position. (again keeping the animation class).</li>
<li>When the transition ends (using the transitionend event), disable animations by removing the CSS class that enables animations and replace it with the CSS class to disable animations.
</ol>
<p>GWT allows you to create any type of element within the &lt;body> tag.  The default set of widgets, unfortunately, do not give you every tag, so you have to write your own class.  Luckily you only need two classes to create any element: one class for elements that contain text, and one class for elements that contain other elements.</p>
<p>Here is the class that contains other elements:</p>
<pre class="brush: java; title: ; notranslate">
package net.lenharts.gwt.sampleiphoneapp.client.util;

import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.ui.*;

public class GenericContainerTag extends ComplexPanel {
	public GenericContainerTag(String tagName) {
		setElement(DOM.createElement(tagName));
	}

	/**
	 * Adds a new child widget to the panel.
	 * 
	 * @param w
	 *            the widget to be added
	 */
	@Override
	public void add(Widget w) {
		add(w, getElement());
	}

	/**
	 * Inserts a widget before the specified index.
	 * 
	 * @param w
	 *            the widget to be inserted
	 * @param beforeIndex
	 *            the index before which it will be inserted
	 * @throws IndexOutOfBoundsException
	 *             if &lt;code&gt;beforeIndex&lt;/code&gt; is out of range
	 */
	public void insert(Widget w, int beforeIndex) {
		insert(w, getElement(), beforeIndex, true);
	}
}
</pre>
<p>To create the element, you pass in the name of the tag.  For instance, if you want to create a &lt;ul> tag, you create it like so</p>
<pre class="brush: java; title: ; notranslate">
GenericContainerTag ul = new GenericContainerTag(&quot;ul&quot;);
</pre>
<p>The class for elements that contain text is a bit more complicated, especially since we&#8217;re enabling iPhone specific events here.  If you were to take out the event code, you&#8217;d find this to be much smaller.  Plus it tries to wire touch events for the iPhone, and click events for all other browsers.  For now, don&#8217;t worry about the details, let&#8217;s just skip down to how to create it. </p>
<pre class="brush: java; title: ; notranslate">
package net.lenharts.gwt.sampleiphoneapp.client.util;

//based on Label.java source code that comes with GWT

import com.google.gwt.user.client.ui.*;
import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.Element;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.shared.GwtEvent;
import com.google.gwt.event.shared.HandlerRegistration;

public class GenericTextTag&lt;E&gt; extends Widget implements HasText {

	private boolean mMovedAfterTouch = false;
	private E mAttachedInfo;

	private boolean mWantsEvents = false;
	private boolean mEventsWiredUp = false;
	HandlerRegistration mHandlerRegistration;

	public GenericTextTag(String tagName) {
		setElement(Document.get().createElement(tagName));
	}

	@Override
	protected void onLoad() {
		if (mWantsEvents) {
			wireUpEvents();
		}
	}

	private void wireUpEvents() {
		if (!mEventsWiredUp &amp;&amp; this.isAttached()) {
			if (hasTouchEvent(this.getElement())) {
				registerDomTouchEvents();
			} else {
				// used for debugging:
				mHandlerRegistration = this.addDomHandler(new ClickHandler() {
					@Override
					public void onClick(ClickEvent event) {
						event.preventDefault();
						fireTouchClick();
					}
				}, ClickEvent.getType());
			}
			mEventsWiredUp = true;
		}
	}

	private void wireDownEvents() {
		if (mEventsWiredUp) {
			if (hasTouchEvent(this.getElement())) {
				unRegisterDomTouchEvents();
			} else {
				mHandlerRegistration.removeHandler();
			}
		}
		mEventsWiredUp = false;
	}

	@Override
	protected void onUnload() {
		wireDownEvents();
	}

	public GenericTextTag(String tagName, String text) {
		this(tagName);
		setText(text);
	}

	public void setAttachedInfo(E info) {
		mAttachedInfo = info;
	}

	public final HandlerRegistration addHandler(
			final TouchClickEvent.TouchClickHandler&lt;E&gt; handler) {
		if (!mWantsEvents) {
			mWantsEvents = true;
			wireUpEvents();
		}
		return this
				.addHandler(
						handler,
						(GwtEvent.Type&lt;TouchClickEvent.TouchClickHandler&lt;E&gt;&gt;) TouchClickEvent
								.getType());
	}

	public E getAttachedInfo() {
		return mAttachedInfo;
	}

	private native void registerDomTouchEvents() /*-{
		var instance = this;
		var element = this.@net.lenharts.gwt.sampleiphoneapp.client.util.GenericTextTag::getElement()();

		element.ontouchstart = function(e){
				instance.@net.lenharts.gwt.sampleiphoneapp.client.util.GenericTextTag::onDomTouchStart()();
		};

		element.ontouchmove = function(e){
				instance.@net.lenharts.gwt.sampleiphoneapp.client.util.GenericTextTag::onDomTouchMove()();
		};

		element.ontouchend = function(e){
				instance.@net.lenharts.gwt.sampleiphoneapp.client.util.GenericTextTag::onDomTouchEnd()();
		};
	}-*/;

	private native void unRegisterDomTouchEvents() /*-{
		var instance = this;
		var element = this.@net.lenharts.gwt.sampleiphoneapp.client.util.GenericTextTag::getElement()();

		element.ontouchstart = null;

		element.ontouchmove = null;

		element.ontouchend = null;
	}-*/;

	public void onDomTouchStart() {
		mMovedAfterTouch = false;
	}

	public void onDomTouchMove() {
		mMovedAfterTouch = true;
	}

	public void onDomTouchEnd() {
		if (mMovedAfterTouch) {
			return;
		}

		fireTouchClick();
	}

	private void fireTouchClick() {
		fireEvent(new TouchClickEvent&lt;E&gt;(this));
	}

	public String getText() {
		return getElement().getInnerText();
	}

	public void setText(String text) {
		getElement().setInnerText(text);
	}

	private static native boolean hasTouchEvent(Element e) /*-{
		var ua = navigator.userAgent.toLowerCase();

		if (ua.indexOf(&quot;safari&quot;) != -1 &amp;&amp;
			ua.indexOf(&quot;applewebkit&quot;) != -1 &amp;&amp;
			ua.indexOf(&quot;mobile&quot;) != -1) 
		{    	
			return true;
		}
		else 
		{
			return false;
		}
	}-*/;

}
</pre>
<p>The code below creates an &lt;li> tag that contains the text &#8220;Hello World!&#8221;.  The &#8220;Hello World!&#8221; test is not fixed.  The class has getter and setter methods for changing the text too.</p>
<pre class="brush: java; title: ; notranslate">
GenericTextTag&lt;String&gt; li = new GenericTextTag&lt;String&gt;(&quot;li&quot;, &quot;Hello World!&quot;);
</pre>
<p><strong>GWT Does Not Have to be Ugly</strong></p>
<p>As you can see in the examples above, you can create any HTML tag, and you can use any CSS style you like.  The sky is the limit on how you style your GWT application.  Many people see the GWT examples and they have an &#8220;application&#8221; feel to it.  Granted the built-in widgets encourage this, but as you can see, you are not restricted to their widgets and you can have a more &#8220;document&#8221; feel to your webpage.  You have complete control of the body tag.</p>
<p><strong>Why GWT?</strong></p>
<p>For me, the difference between GWT and Javascript is whether you want to work with a static language like Java, or a dynamic language like Javascript.  I assert, with little proof, that static languages are better.  They provide a much deeper verification of your code which I feel is necessary of any sizable application.  I remember the VBScript days, and I don&#8217;t want to return to shipping bugs that are trival to find by a static language compiler.</p>
<p>There are issues with the size of the javascript download that both sides claim to be better.</p>
<ul>
<li>Pure Javascript is smaller because you include a library from Google that the user has already downloaded plus your small javascript code that you write</li>
<li>GWT is smaller, because the GWT compiler is highly optimized to remove dead code and to restructure your code to be as small as possible.  For instance, if you only use 10% of a library, then the downloaded code includes only 10% of the library.</li>
</ul>
<p>Small apps can work OK with a dynamic language, with the potential that it will have less code to download.  However for larger applications, the GWT compiler will produce smaller code as compared to hand written, minified Javascript and the static language will help reduce the number of bugs.</p>
]]></content:encoded>
			<wfw:commentRss>http://clay.lenharts.net/blog/2009/05/25/gwt-is-flexible-iphone-demo/feed/</wfw:commentRss>
		<slash:comments>44</slash:comments>
		</item>
		<item>
		<title>OpenID is great</title>
		<link>http://clay.lenharts.net/blog/2009/03/07/openid-is-great/</link>
		<comments>http://clay.lenharts.net/blog/2009/03/07/openid-is-great/#comments</comments>
		<pubDate>Sat, 07 Mar 2009 14:49:05 +0000</pubDate>
		<dc:creator><![CDATA[Clay Lenhart]]></dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[OpenID]]></category>

		<guid isPermaLink="false">http://clay.lenharts.net/blog/?p=55</guid>
		<description><![CDATA[It&#8217;s so easy to set up, I can&#8217;t believe I haven&#8217;t done it before. All you need is an openid account (like www.myopenid.com, which they seem to like), and a static HTML page. You don&#8217;t really need the static HTML &#8230; <a href="http://clay.lenharts.net/blog/2009/03/07/openid-is-great/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>It&#8217;s so easy to set up, I can&#8217;t believe I haven&#8217;t done it before.<br />
<span id="more-55"></span><br />
All you need is an openid account (like <a href="http://www.myopenid.com">www.myopenid.com</a>, which <a href="http://www.intertwingly.net/blog/2007/01/03/OpenID-for-non-SuperUsers">they</a> seem to like), and a static HTML page.</p>
<p>You don&#8217;t really need the static HTML page, but it allows you to switch openid accounts easily.</p>
<p>To login to an openid enabled site, like <a href="http://sourceforge.net/account/login.php">sourceforge.net</a>, you enter your static HTML page into the openid field, for instance I use <a href="http://clay.lenharts.net/openid/">http://clay.lenharts.net/openid/</a>. The static HTML page contains some links that point to your real openid account.  After logging in you are done.</p>
]]></content:encoded>
			<wfw:commentRss>http://clay.lenharts.net/blog/2009/03/07/openid-is-great/feed/</wfw:commentRss>
		<slash:comments>25</slash:comments>
		</item>
		<item>
		<title>The &#8220;Many Core&#8221; Problem</title>
		<link>http://clay.lenharts.net/blog/2008/10/25/the-many-core-problem/</link>
		<comments>http://clay.lenharts.net/blog/2008/10/25/the-many-core-problem/#comments</comments>
		<pubDate>Sat, 25 Oct 2008 23:03:31 +0000</pubDate>
		<dc:creator><![CDATA[Clay Lenhart]]></dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[Languages]]></category>
		<category><![CDATA[F#]]></category>
		<category><![CDATA[Multithread]]></category>

		<guid isPermaLink="false">http://clay.lenharts.net/blog/?p=43</guid>
		<description><![CDATA[We, as developers, have a problem.  CPUs will continue to have more cores, and each core is not going to be any faster.  The only way to write faster applications is to write multithreaded code, which has two challenges: 1) Multithreaded code is complex to write and think about. 2)Multithreaded code is difficult to test.  From what I've seen, people are pursuing 4 approaches. 
 <a href="http://clay.lenharts.net/blog/2008/10/25/the-many-core-problem/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>We, as developers, have a problem.  CPUs will continue to have more cores, and each core is not going to be any faster.  The only way to write faster applications is to write multithreaded code, which has two challenges:</p>
<ul>
<li>Multithreaded code is complex to write and think about.</li>
<li>Multithreaded code is difficult to test.</li>
</ul>
<p>From what I&#8217;ve seen, people are pursuing 4 approaches. <span id="more-43"></span></p>
<p><strong>Better Languages</strong></p>
<p>If languages are the whole answer, the language has to make it impossible to write multithreaded bugs, otherwise you only address the first problem (the complexity).</p>
<p>Erlang is one such language that removes whole class of multithreaded bugs. Erlang&#8217;s approach is to isolate the threads, and give them a way to pass messages to each other.  However programming in Erlang is awkward and arguably it makes the code more complex.</p>
<p>Other languages, like Clojure and F#, take a different approach and make it easier to write and deal with multithreaded issues, however they don&#8217;t prevent you from writing multithreaded bugs.  These languages do not address the whole problem as you still need a way to test the code.</p>
<p><strong>Better Libraries</strong></p>
<p>Microsoft has a library for .Net called <a href="http://msdn.microsoft.com/en-us/magazine/cc163340.aspx">Parallel Task Library </a>to make it easier to write multithreaded code.  Need to operate on each element in an array?  Use the Parallel.For() method.  This library makes it easier to think and write multithreaded code, but it doesn&#8217;t make it any easier to test.</p>
<p><strong>Static Code Analyzer</strong></p>
<p>Java has a static code analyzer that is able to find multithreading bugs called <a href="http://findbugs.sourceforge.net/">FindBugs</a>.  It looks at your code and reports any code that will cause multithreaded bugs.  This would address the second issue, because it, in theory, reports all threading bugs.  It doesn&#8217;t however address the first issue, making the code easier to write.</p>
<p><strong>Testing with Deterministic Threads</strong><strong><br />
</strong></p>
<p>Microsoft is going in a different direction.  They are working on something called <a href="http://research.microsoft.com/~madanm/papers/osdi2008-CHESS.pdf">CHESS</a> that makes your unit tests find multithreaded bugs.  It does this by taking over the scheduler and sysmatically repeating each test, weaving the threads differently each time to exercise every possible way the scheduler could run the code.  However it requires us to to write a set of tests that finds *all* the threading bugs.  Since it is common to write unit tests with less than 100% coverage, a code coverage tool should be used to write more tests.</p>
<p><strong>Conclusion</strong></p>
<p>The good news is that there appears to be a variety of approaches to the problem and the whole answer will likely involve a combination of language or library enhancements and analyser or testing enhancements that are already in the works.</p>
]]></content:encoded>
			<wfw:commentRss>http://clay.lenharts.net/blog/2008/10/25/the-many-core-problem/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>Functional Language Explosion</title>
		<link>http://clay.lenharts.net/blog/2008/10/18/functional-language-exploision/</link>
		<comments>http://clay.lenharts.net/blog/2008/10/18/functional-language-exploision/#comments</comments>
		<pubDate>Sat, 18 Oct 2008 10:50:02 +0000</pubDate>
		<dc:creator><![CDATA[Clay Lenhart]]></dc:creator>
				<category><![CDATA[Languages]]></category>
		<category><![CDATA[F#]]></category>
		<category><![CDATA[Functional Langauges]]></category>
		<category><![CDATA[Immutable]]></category>

		<guid isPermaLink="false">http://clay.lenharts.net/blog/?p=41</guid>
		<description><![CDATA[There is suddenly a lot of interest in functional languages recently.  The two advantages are writing a DSL (Domain Specific Language) and writing concurrent code. The languages that seem to come up are Clojure (JVM), F# (based on OCaml, Haskell, and ML) (.Net CLR), and Erlang (JVM).
 <a href="http://clay.lenharts.net/blog/2008/10/18/functional-language-exploision/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>There is suddenly a lot of interest in <a href="http://en.wikipedia.org/wiki/Functional_programming">functional languages </a>recently.  The two advantages are</p>
<ul>
<li>Writing a DSL (Domain Specific Language)</li>
<li>Writing concurrent code</li>
</ul>
<p>The languages that seem to come up are:</p>
<ul>
<li><a href="http://clojure.org/">Clojure</a> (JVM)</li>
<li><a href="http://msdn.microsoft.com/en-gb/fsharp/default.aspx">F#</a> (based on OCaml, Haskell, and ML) (.Net CLR)</li>
<li><a href="http://www.erlang.org/">Erlang</a> <span style="text-decoration: line-through;">(JVM)</span></li>
</ul>
<p>I&#8217;m not particularly interested in DSL (despite my last post on <a href="http://clay.lenharts.net/blog/2008/10/18/code-generator-built-in-to-vs-2008/">code generators</a>), however as CPUs contain more and more cores, we&#8217;ll need a way to safely write multithreaded code.</p>
<p>The Clojure project has an interesting post on its approach on <a href="http://clojure.org/state">simplifying multithreaded code</a>.</p>
<p>Erlang handles concurrency by only having local variables and providing a way to send messages to and from other threads.</p>
<p>Lastly, <a href="http://www.osl.iu.edu/research/mpi.net/">MPI </a>is a .Net library for distributed processing where the same program executes multiple times and each instance communicates with each other using message passing which sounds very Erlang-like.</p>
]]></content:encoded>
			<wfw:commentRss>http://clay.lenharts.net/blog/2008/10/18/functional-language-exploision/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>GWT for Web Applications</title>
		<link>http://clay.lenharts.net/blog/2008/10/18/gwt-for-web-applications/</link>
		<comments>http://clay.lenharts.net/blog/2008/10/18/gwt-for-web-applications/#comments</comments>
		<pubDate>Sat, 18 Oct 2008 10:47:01 +0000</pubDate>
		<dc:creator><![CDATA[Clay Lenhart]]></dc:creator>
				<category><![CDATA[Architecture]]></category>
		<category><![CDATA[GWT]]></category>
		<category><![CDATA[Web Application]]></category>

		<guid isPermaLink="false">http://clay.lenharts.net/blog/?p=42</guid>
		<description><![CDATA[There are several approaches for writing web applications, each with their own advantages.  GWT is a new framework with its own niche. Your standard ASP.Net (or JSP/PHP/etc) w/ Ajax and JQuery (or other Javascript library) Java WebStart or .Net ClickOnce &#8230; <a href="http://clay.lenharts.net/blog/2008/10/18/gwt-for-web-applications/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
				<content:encoded><![CDATA[<p>There are several approaches for writing web applications, each with their own advantages.  GWT is a new framework with its own niche.</p>
<ul>
<li>Your standard ASP.Net (or JSP/PHP/etc) w/ Ajax and JQuery (or other Javascript library)</li>
<li><a href="http://java.sun.com/javase/technologies/desktop/javawebstart/index.jsp">Java WebStart </a>or .Net <a href="http://en.wikipedia.org/wiki/ClickOnce">ClickOnce</a></li>
<li><a href="http://code.google.com/webtoolkit/">GWT</a> w/ Webservices</li>
</ul>
<p><span id="more-42"></span><br />
<strong>ASP.Net (or JSP/PHP/etc) &#8211; for Dynamic Websites<br />
</strong></p>
<p>ASP.Net is great, because it will run on any browser, but it difficult and error prone to write Javascript code, and many times the application or site isn&#8217;t very interactive or responsive.</p>
<p>A coworker suggests that this is good for a &#8220;dynamic website&#8221;, rather than a full blown &#8220;web application&#8221;.  It certainly has a web site feel, rather than an application feel to it.  See the GWT demos below to see what I&#8217;m talking about.</p>
<p><strong>Java WebStart or .Net ClickOnce &#8211; for Internal Corporate Applications<br />
</strong></p>
<p>This, however, provides are great environment for writing interactive applications, however it requires either Java or .Net on the client.  Some users do not have permissions necessary to install Java and .Net.</p>
<p><strong>GWT w/ Webservices &#8211; for Public Applications<br />
</strong></p>
<p>GWT is a great idea that compiles Java code into Javascript to give you an HTML/Javascript web application.    It allows you to have *a lot* of javascript code that does not talk with the web server.  Be sure to check out these <a href="http://code.google.com/webtoolkit/examples/">GWT demos</a>.</p>
<p>You can&#8217;t use the Java library with GWT, however you get a great GWT UI library, and you can call a webservice to do anything you like, for instance to make database calls.</p>
<p>As a C# developer, I find this great, because the learning curve is small.  The Java language is so close to C#, and I don&#8217;t have to learn the Java library.</p>
]]></content:encoded>
			<wfw:commentRss>http://clay.lenharts.net/blog/2008/10/18/gwt-for-web-applications/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
