将ASP.NET Web应用程序限制为仅为给定数量的并发用户提供服务的好方法是什么?
一些要求是:
http://maven.glassfish.org/content/groups/glassfish/看起来应该是GlassFish的官方Maven存储库,但它目前只承载了glassfish-embedded-all的3.1.1-b05版本(参见http:/ /maven.glassfish.org/content/groups/glassfish/org/glassfish/extras/glassfish-embedded-all/).
http://download.java.net/maven/glassfish/org/glassfish/extras/与Embedded GlassFish的网站(Embedded Jars)相关联.它看起来不像官方的Maven存储库,但最多可容纳3.1.1-b11(在http://download.java.net/maven/glassfish/org/glassfish/extras/glassfish-embedded-all/).
所以问题是哪个是可靠的存储库来获取嵌入式GlassFish的Maven依赖项.
我正在尝试开发通用命令处理器。我想创建实现给定接口的命令处理程序类。我将使用控制反转根据收到的命令类型动态创建适当类的实例。然后我想以通用方式调用类的“执行”方法。
我可以使用协变类型参数来完成这项工作,但在这种情况下,我不能使用泛型类型参数作为方法参数。
似乎逆变方法应该有效,因为它允许我根据需要声明方法参数,但不幸的是,类的实例无法转换为基接口。
下面的代码举例说明了这个问题:
using System;
using System.Diagnostics;
namespace ConsoleApplication2
{
// Command classes
public class CommandMessage
{
public DateTime IssuedAt { get; set; }
}
public class CreateOrderMessage : CommandMessage
{
public string CustomerName { get; set; }
}
// Covariant solution
public interface ICommandMessageHandler1<out T> where T : CommandMessage
{
void Execute(CommandMessage command);
}
public class CreateOrderHandler1 : ICommandMessageHandler1<CreateOrderMessage>
{
public void Execute(CommandMessage command)
{
// An explicit typecast is required
var createOrderMessage = (CreateOrderMessage) command;
Debug.WriteLine("CustomerName: " …Run Code Online (Sandbox Code Playgroud) 在Upshot.js库中,它是ASP.NET MVC 4 Beta 的http://www.asp.net/single-page-application功能的一部分,如何配置它与使用WCF开发的OData服务一起使用数据服务?
源代码包含"upshot.ODataDataProvider"; 它怎么用?
鉴于正在多个服务器上同时执行的Django应用程序,该应用程序如何记录到单个共享日志文件(在网络共享中),而不保持此文件在独占模式下永久打开?
当您想要利用日志流时,这种情况适用于托管在Windows Azure网站上的Django应用程序.
在这个示例项目中,我尝试使用ConcurrentLogHandler,如下所示:
'ConcurrentLogHandler':{
'level': 'DEBUG',
'class': 'cloghandler.ConcurrentRotatingFileHandler',
'formatter': 'verbose',
'filename': os.getenv('LOGFILE', 'django.log')
},
Run Code Online (Sandbox Code Playgroud)
from time import gmtime, strftime
import logging
from django.http import HttpResponse
logger = logging.getLogger(__name__)
def home(request):
current_time = strftime("%Y-%m-%d %H:%M:%S", gmtime())
logger.info('home ' + current_time)
return HttpResponse("Hello from Django! It is now " + current_time + ".\n")
Run Code Online (Sandbox Code Playgroud)
写入日志,但在网站运行时似乎没有刷新文件.另外,如果我尝试使用FTP读取文件我得到这个消息:"因为它正由另一个进程使用550个进程无法访问文件."
如果我停止应用程序,文件将关闭,我可以读取该文件并查看其中的所有日志.
我假设ConcurrentLogHandler将允许对日志文件的共享访问.这个假设是错的吗?是否需要一些额外的配置?还有其他选择吗?
是否可以使用Play Framework 2.2在Scala中创建一个通用函数,它将任意对象序列化为JSON,而不必提供编写器或格式化程序?
例如,这个非通用代码将为Customer创建一个JSON响应:
import play.api.libs.json._
import play.api.libs.functional.syntax._
case class Customer(id: Int, name: String)
object scratch {
val p = Customer(1, "n")
//> p : Customer = Customer(1,n)
def createJsonResponseCustomer(data: Customer) = {
implicit val formatter = Json.format[Customer]
Json.obj("success" -> true, "data" -> Json.toJson[Customer](data))
}
createJsonResponseCustomer(p)
//> res0: play.api.libs.json.JsObject = {"success":true,"data":{"id":1,"name":"n"}}
}
Run Code Online (Sandbox Code Playgroud)
为了避免为每个不同的对象定义格式化程序,我想创建一个这样的通用函数:
def createJsonResponse[T](data: T) = {
implicit val formatter = Json.format[T]
Json.obj("success" -> true, "data" -> Json.toJson[T](data))
}
Run Code Online (Sandbox Code Playgroud)
但是,这种尝试产生错误No unapply function found的Json.format[T].
换句话说,这有效:
def …Run Code Online (Sandbox Code Playgroud) 我想在Scala中编写一个thrift服务实现(使用Scrooge)但不使用Finagle,因为我无法为Finagle服务器编写ruby/python客户端.问题是,使用scrooge服务似乎没有实现"处理器"类.
假设我有这样的节俭定义:
service TestService {
void testFunction(1: string message);
}
Run Code Online (Sandbox Code Playgroud)
我使用scrooge生成scala文件,当我尝试使用thrift的标准实现来scala运行服务器:
val st = new TServerSocket(9999)
val processor = new TestService.Processor(new TestServiceImpl)
val arg = new TThreadPoolServer.Args(st)
arg.processor(processor)
val server = new TThreadPoolServer(arg)
server.serve()
Run Code Online (Sandbox Code Playgroud)
生成的TestService对象似乎没有Processor内部类.不知道如何在没有Finagle的情况下做到这一点?或者作为另一种解决方案,如何将一个python或ruby客户端写入finagle thrift服务器?
如何将实体异步保存到Windows Azure表服务?
下面的代码同步工作,但在尝试异步保存时引发异常.
这个说法:
context.BeginSaveChangesWithRetries(SaveChangesOptions.Batch,
(asyncResult => context.EndSaveChanges(asyncResult)), null);
Run Code Online (Sandbox Code Playgroud)
System.ArgumentException中的结果:"当前对象未生成异步结果.参数名称:asyncResult".
此外,在异步保存时创建服务上下文的正确模式是什么?我应该为每个写操作创建一个单独的上下文吗?是否太昂贵(例如需要通过网络拨打电话)?
TableStorageWriter.cs:
using System;
using System.Data.Services.Client;
using System.Diagnostics;
using Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.StorageClient;
namespace WorkerRole1
{
public class TableStorageWriter
{
private const string _tableName = "StorageTest";
private readonly CloudStorageAccount _storageAccount;
private CloudTableClient _tableClient;
public TableStorageWriter()
{
_storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));
_tableClient = _storageAccount.CreateCloudTableClient();
_tableClient.CreateTableIfNotExist(_tableName);
}
public void Write(string message)
{
try
{
DateTime now = DateTime.UtcNow;
var entity = new StorageTestEntity
{
Message = message,
PartitionKey = string.Format("{0:yyyy-MM-dd}", now),
RowKey = …Run Code Online (Sandbox Code Playgroud) 这是一个关于AngularJS应用程序路由的问题.它没有使用MVC,它确实使用WebAPI作为后端(这些路由工作正常).
我使用VS SPA模板作为基线:http://visualstudiogallery.msdn.microsoft.com/5af151b2-9ed2-4809-bfe8-27566bfe7d83
我遇到的问题是我的DefaultRouteHandler似乎总是在我的角度定义路线之前被击中.例如,我有一个/ wageagreement/new的路由,但.cshtml文件位于/ views/wageagreement/detail中.我的角度路线在app.js中定义如下:
$stateProvider
.state('wageagreement-new', {
url: '/wageagreement/new',
templateUrl: '/views/wageagreement/detail',
controller: 'wageAgreementDetailsCtrl'
})
Run Code Online (Sandbox Code Playgroud)
如果我转到页面/ wageagreement/new,我的DefaultRouteHandler(见下文)首先被命中,文件路径是/ wageagreement/new.由于此文件不存在,我收到404错误.然后,我的角度路径似乎开始,页面从/ view/wageagreement/detail加载得很好.因此,对于每个页面,我得到错误404闪烁然后我得到正确的页面.有没有办法让这项工作?我开始认为我的.cshtml文件可能必须与我的路线相匹配才能使其正常工作.
public class DefaultRouteHandler : IRouteHandler
{
public IHttpHandler GetHttpHandler(RequestContext requestContext)
{
// Use cases:
// ~/ -> ~/views/index.cshtml
// ~/about -> ~/views/about.cshtml or ~/views/about/index.cshtml
// ~/views/about -> ~/views/about.cshtml
// ~/xxx -> ~/views/404.cshtml
var filePath = requestContext.HttpContext.Request.AppRelativeCurrentExecutionFilePath;
if (filePath == "~/")
{
filePath = "~/views/touranalysis/index.cshtml";
}
else
{
if (!filePath.StartsWith("~/views/", StringComparison.OrdinalIgnoreCase))
{
filePath = filePath.Insert(2, "views/");
}
if …Run Code Online (Sandbox Code Playgroud) 在Play Framework 2.3中,一个动作可以产生一个成功的未来调用的结果,如下所示:
def index = Action.async {
val futureInt = scala.concurrent.Future { intensiveComputation() }
futureInt.map(i => Ok("Got result: " + i))
}
Run Code Online (Sandbox Code Playgroud)
但是,一个行动如何处理未来失败的呼吁,即通过呼叫failure()而不是通过呼叫完成的未来success()?
例如,一个动作怎么能产生一个InternalServerError结果,并且在未来的失败中可以抛出消息?
onComplete并且onFailure回调似乎不适合动作的流程(它需要从成功的未来或失败的结果返回结果).