fixes for daily build target

misc updates to ref documentation
use signed NNS assembly based on spring.net key
sync vs.net 2003 solution
This commit is contained in:
markpollack
2008-06-17 02:13:28 +00:00
parent d56ad5a9dc
commit fc584813bb
16 changed files with 664 additions and 962 deletions

View File

@@ -0,0 +1,140 @@
////<examples>
using System;
using System.IO;
using System.Reflection;
using System.Text.RegularExpressions;
using System.Threading;
using Spring.Threading;
namespace Spring.Examples.Pool
{
public class Grep : IRunnable
{
private string file;
private string regexPattern;
public class Match
{
string fileName, line;
int lineNum;
public Match(string fileName, int lineNum, string line)
{
this.fileName = fileName;
this.lineNum = lineNum;
this.line = line;
}
public void Print()
{
Console.Out.WriteLine("thread #{0}: {1}: {2}: {3}", Thread.CurrentThread.GetHashCode(), fileName, lineNum, line);
}
}
public class Error
{
string file;
Exception e;
public Error(string file, Exception e)
{
this.file = file;
this.e = e;
}
public void Print()
{
Console.Out.WriteLine("file [{0}]: {1}", file, e.Message);
}
}
public Grep(string file, string regexPattern)
{
this.file = file;
this.regexPattern = regexPattern;
}
public void Run()
{
try
{
int lineNum = 1;
using (TextReader r = File.OpenText(file))
{
string line = null;
while ((line = r.ReadLine()) != null)
{
if (Regex.IsMatch(line, Regex.Escape(regexPattern), RegexOptions.Singleline))
{
new Grep.Match(file, lineNum, line).Print();
}
lineNum++;
}
}
}
catch (Exception e)
{
new Grep.Error(file, e).Print();
}
}
}
public class ParallelGrep
{
//// <example name="parallel-grep-class">
private PooledQueuedExecutor executor;
public ParallelGrep(int size)
{
executor = new PooledQueuedExecutor(size);
}
public void Recurse(string startPath, string filePattern, string regexPattern)
{
foreach (string file in Directory.GetFiles(startPath, filePattern))
{
executor.Execute(new Grep(file, regexPattern));
}
foreach (string directory in Directory.GetDirectories(startPath))
{
Recurse(directory, filePattern, regexPattern);
}
}
public void Stop()
{
executor.Stop();
}
//// </example>
//// <example name="parallel-grep-main">
public static void Main(string[] args)
{
if (args.Length < 3)
{
Console.Out.WriteLine("usage: {0} regex directory file-pattern [pool-size]", Assembly.GetEntryAssembly().CodeBase);
Environment.Exit(1);
}
string regexPattern = args[0];
string startPath = args[1];
string filePattern = args[2];
int size = 10;
try
{
size = Int32.Parse(args[3]);
}
catch
{
}
Console.Out.WriteLine ("pool size {0}", size);
ParallelGrep grep = new ParallelGrep(size);
grep.Recurse(startPath, filePattern, regexPattern);
grep.Stop();
}
//// </example>
}
}
//// </examples>

View File

@@ -0,0 +1,190 @@
////<examples>
using System;
using System.Collections;
using System.Threading;
using Spring.Pool;
using Spring.Threading;
namespace Spring.Examples.Pool
{
/// <summary>
/// Factory of <see cref="QueuedExecutor"/> istances.
/// </summary>
//// <example name='factory-declaration'>
public class QueuedExecutorPoolableFactory : IPoolableObjectFactory
{
//// </example>
//// <example name='destroy'>
void IPoolableObjectFactory.DestroyObject(object o)
{
// ah, self documenting code:
// Here you can see that we decided to let the
// executor process all the currently queued tasks.
QueuedExecutor executor = o as QueuedExecutor;
executor.ShutdownAfterProcessingCurrentlyQueuedTasks();
}
//// </example>
//// <example name="validate">
bool IPoolableObjectFactory.ValidateObject(object o)
{
QueuedExecutor executor = o as QueuedExecutor;
return executor.Thread != null;
}
//// </example>
//// <example name='activate'>
void IPoolableObjectFactory.ActivateObject(object o)
{
QueuedExecutor executor = o as QueuedExecutor;
executor.Restart();
}
//// </example>
//// <example name='passivate'>
void IPoolableObjectFactory.PassivateObject(object o)
{
}
//// </example>
//// <example name='make'>
object IPoolableObjectFactory.MakeObject()
{
// to actually make this work as a pooled executor
// use a bounded queue of capacity 1.
// If we don't do this one of the queued executors
// will accept all the queued IRunnables as, by default
// its queue is unbounded, and the PooledExecutor
// will happen to always run only one thread ...
return new QueuedExecutor(new BoundedBuffer(1));
}
//// </example>
}
//// <example name="holder">
public class PooledObjectHolder : IDisposable
{
IObjectPool pool;
object pooled;
/// <summary>
/// Builds a new <see cref="PooledObjectHolder"/>
/// trying to borrow an object form it
/// </summary>
/// <param name="pool"></param>
private PooledObjectHolder(IObjectPool pool)
{
this.pool = pool;
this.pooled = pool.BorrowObject();
}
/// <summary>
/// Allow to access the borrowed pooled object
/// </summary>
public object Pooled
{
get
{
return pooled;
}
}
/// <summary>
/// Returns the borrowed object to the pool
/// </summary>
public void Dispose()
{
pool.ReturnObject(pooled);
}
/// <summary>
/// Creates a new <see cref="PooledObjectHolder"/> for the
/// given pool.
/// </summary>
public static PooledObjectHolder UseFrom(IObjectPool pool)
{
return new PooledObjectHolder(pool);
}
}
//// </example>
public class PooledQueuedExecutor : IExecutor
{
Spring.Pool.SimplePool pool;
private IList syncs;
class Queuer
{
IObjectPool pool;
IRunnable runnable;
private ISync sync;
public Queuer (IObjectPool pool, IRunnable runnable)
{
this.pool = pool;
this.runnable = runnable;
this.sync = new Latch();
}
public void Queue ()
{
//// <example name="execute">
using (PooledObjectHolder holder = PooledObjectHolder.UseFrom(pool))
{
QueuedExecutor executor = (QueuedExecutor) holder.Pooled;
executor.Execute(runnable);
}
//// </example>
sync.Release();
}
public static ISync Queue (IObjectPool pool, IRunnable runnable)
{
Queuer queuer = new Queuer(pool, runnable);
Thread thread = new Thread(new ThreadStart(queuer.Queue));
thread.Start();
return queuer.Sync;
}
public ISync Sync
{
get
{
return sync;
}
}
}
public PooledQueuedExecutor(int size)
{
//// <example name="create-pool">
pool = new SimplePool(new QueuedExecutorPoolableFactory(), size);
//// </example>
syncs = ArrayList.Synchronized(new ArrayList());
}
public PooledQueuedExecutor()
: this(10)
{
}
public void Execute(IRunnable runnable)
{
// queue the task and remember its ISync ...
syncs.Add(Queuer.Queue(pool, runnable));
}
//// <example name="stop">
public void Stop ()
{
// waits for all the grep-task to have been queued ...
foreach (ISync sync in syncs)
{
sync.Acquire();
}
pool.Close();
}
//// </example>
}
}
//// </examples>

View File

@@ -0,0 +1,120 @@
<VisualStudioProject>
<CSHARP
ProjectType = "Local"
ProductVersion = "7.10.3077"
SchemaVersion = "2.0"
ProjectGuid = "{C261D9ED-85C3-4B35-BE48-7156F5B17430}"
>
<Build>
<Settings
ApplicationIcon = ""
AssemblyKeyContainerName = ""
AssemblyName = "Spring.Examples.Pool"
AssemblyOriginatorKeyFile = ""
DefaultClientScript = "JScript"
DefaultHTMLPageLayout = "Grid"
DefaultTargetSchema = "IE50"
DelaySign = "false"
OutputType = "Exe"
PreBuildEvent = ""
PostBuildEvent = ""
RootNamespace = "Spring"
RunPostBuildEvent = "OnOutputUpdated"
StartupObject = ""
>
<Config
Name = "Debug"
AllowUnsafeBlocks = "false"
BaseAddress = "285212672"
CheckForOverflowUnderflow = "false"
ConfigurationOverrideFile = ""
DefineConstants = "DEBUG;TRACE"
DocumentationFile = ""
DebugSymbols = "true"
FileAlignment = "4096"
IncrementalBuild = "false"
NoStdLib = "false"
NoWarn = ""
Optimize = "false"
OutputPath = "bin\Debug\"
RegisterForComInterop = "false"
RemoveIntegerChecks = "false"
TreatWarningsAsErrors = "false"
WarningLevel = "4"
/>
<Config
Name = "Release"
AllowUnsafeBlocks = "false"
BaseAddress = "285212672"
CheckForOverflowUnderflow = "false"
ConfigurationOverrideFile = ""
DefineConstants = "TRACE"
DocumentationFile = ""
DebugSymbols = "false"
FileAlignment = "4096"
IncrementalBuild = "false"
NoStdLib = "false"
NoWarn = ""
Optimize = "true"
OutputPath = "bin\Release\"
RegisterForComInterop = "false"
RemoveIntegerChecks = "false"
TreatWarningsAsErrors = "false"
WarningLevel = "4"
/>
</Settings>
<References>
<Reference
Name = "System"
AssemblyName = "System"
HintPath = "..\..\..\..\..\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.dll"
/>
<Reference
Name = "System.Data"
AssemblyName = "System.Data"
HintPath = "..\..\..\..\..\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.Data.dll"
/>
<Reference
Name = "System.XML"
AssemblyName = "System.Xml"
HintPath = "..\..\..\..\..\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.XML.dll"
/>
<Reference
Name = "log4net"
AssemblyName = "log4net"
HintPath = "..\..\..\lib\Net\1.1\log4net.dll"
/>
<Reference
Name = "System.Web"
AssemblyName = "System.Web"
HintPath = "..\..\..\..\..\..\..\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.Web.dll"
/>
<Reference
Name = "System.Web.Services"
AssemblyName = "System.Web.Services"
HintPath = "..\..\..\..\..\..\..\WINDOWS\Microsoft.NET\Framework\v1.1.4322\System.Web.Services.dll"
/>
<Reference
Name = "Spring.Core"
Project = "{710961A3-0DF4-49E4-A26E-F5B9C044AC84}"
Package = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"
/>
</References>
</Build>
<Files>
<Include>
<File
RelPath = "Examples\Pool\Grep.cs"
SubType = "Code"
BuildAction = "Compile"
/>
<File
RelPath = "Examples\Pool\PooledQueuedExecutor.cs"
SubType = "Code"
BuildAction = "Compile"
/>
</Include>
</Files>
</CSHARP>
</VisualStudioProject>

View File

@@ -0,0 +1,29 @@
Microsoft Visual Studio Solution File, Format Version 8.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spring.Core", "..\..\..\src\Spring\Spring.Core\Spring.Core.2003.csproj", "{710961A3-0DF4-49E4-A26E-F5B9C044AC84}"
ProjectSection(ProjectDependencies) = postProject
EndProjectSection
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spring.Examples.Pool", "Spring.Examples.Pool.csproj", "{C261D9ED-85C3-4B35-BE48-7156F5B17430}"
ProjectSection(ProjectDependencies) = postProject
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfiguration) = preSolution
Debug = Debug
Release = Release
EndGlobalSection
GlobalSection(ProjectConfiguration) = postSolution
{710961A3-0DF4-49E4-A26E-F5B9C044AC84}.Debug.ActiveCfg = Debug|.NET
{710961A3-0DF4-49E4-A26E-F5B9C044AC84}.Debug.Build.0 = Debug|.NET
{710961A3-0DF4-49E4-A26E-F5B9C044AC84}.Release.ActiveCfg = Release|.NET
{710961A3-0DF4-49E4-A26E-F5B9C044AC84}.Release.Build.0 = Release|.NET
{C261D9ED-85C3-4B35-BE48-7156F5B17430}.Debug.ActiveCfg = Debug|.NET
{C261D9ED-85C3-4B35-BE48-7156F5B17430}.Debug.Build.0 = Debug|.NET
{C261D9ED-85C3-4B35-BE48-7156F5B17430}.Release.ActiveCfg = Release|.NET
{C261D9ED-85C3-4B35-BE48-7156F5B17430}.Release.Build.0 = Release|.NET
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
EndGlobalSection
GlobalSection(ExtensibilityAddIns) = postSolution
EndGlobalSection
EndGlobal