Netty Camel样品(Netty Camel samples)

我是Netty的新手。

我正在寻找一些样品。 (优选但不是必须使用Camel Netty Component和Spring)

特别是一个使用TCP消息的示例Netty应用程序。

另外,我如何编写可以测试这个netty应用程序的JUnit测试?

谢谢,Dar


I'm a newbie to Netty.

I'm looking for some samples. (Preferably but not necessarity using Camel Netty Component and Spring)

Specifically a sample Netty app that consumes TCP messages.

Also how can I write a JUnit test that can test this netty app?

Thanks, Dar


原文:https://stackoverflow.com/questions/8419245
2023-09-27 07:09

满意答案

这里有足够的例子来使用表达式来获取一个属性或字段的名称来启动它:

public static MemberInfo GetMemberInfo<T, U>(Expression<Func<T, U>> expression)
{
    var member = expression.Body as MemberExpression;
    if (member != null)
        return member.Member;

    throw new ArgumentException("Expression is not a member access", "expression");
}

调用代码如下所示:

public class Program
{
    public string Name
    {
        get { return "My Program"; }
    }

    static void Main()
    {
        MemberInfo member = ReflectionUtility.GetMemberInfo((Program p) => p.Name);
        Console.WriteLine(member.Name);
    }
}

尽管如此: (Program p) => p.Name的简单(Program p) => p.Name实际上涉及相当多的工作(并且可能花费大量时间)。 考虑缓存结果,而不是经常调用该方法。


Here's enough of an example of using Expressions to get the name of a property or field to get you started:

public static MemberInfo GetMemberInfo<T, U>(Expression<Func<T, U>> expression)
{
    var member = expression.Body as MemberExpression;
    if (member != null)
        return member.Member;

    throw new ArgumentException("Expression is not a member access", "expression");
}

Calling code would look like this:

public class Program
{
    public string Name
    {
        get { return "My Program"; }
    }

    static void Main()
    {
        MemberInfo member = ReflectionUtility.GetMemberInfo((Program p) => p.Name);
        Console.WriteLine(member.Name);
    }
}

A word of caution, though: the simple statment of (Program p) => p.Name actually involves quite a bit of work (and can take measurable amounts of time). Consider caching the result rather than calling the method frequently.

相关问答

更多

使用lambda表达式获取属性名称和类型(Get property name and type using lambda expression)

这里有足够的例子来使用表达式来获取一个属性或字段的名称来启动它: public static MemberInfo GetMemberInfo<T, U>(Expression<Func<T, U>> expression) { var member = expression.Body as MemberExpression; if (member != null) return member.Member; throw new ArgumentExcep...

动态lambda表达式(OrderBy)和可空属性类型(Dynamic lambda expression (OrderBy) and nullable property type)

没有理由使用IComparable 。 实际上,许多类似的类型都没有实现IComparable 。 只需使用您传递的任何运行时类型: var finalExpression = Expression.Call( typeof (Queryable), "OrderBy", new[] { list.ElementType, propertyToOrder.Type }, list.Expression, Expression.Lambda(propertyT...

lambda表达式作为属性(lambda Expression as a property)

你可以尝试这样的事情,不必将属性名称编码为字符串,如果这是你所说的强类型的意思: class CellInfo<T> { public string Title { get; set; } public string FormatString { get; set; } public Func<T, object> Selector { get; set; } } Dictionary<string, CellInfo<Person>> dict = new Dictio...

从属性名称获取属性lambda(其中属性类型可以为空)(get property lambda from property Name (Where property type can be nullable))

其实我不认为这个问题与Nullable类型有关,而是与值类型有关。 用一个decimal类型的属性(而不是Nullable<decimal> )来尝试你的方法:它会以同样的方式失败。 看看如何为值和引用类型生成表达式树(例如使用LinqPad) Expression<Func<T, object>> lambda = x => x.AString; (参考类型) =>正文是MemberExpression Expression<Func<T, object>> lambda = x => x.AD...

使用lambda表达式获取属性或类型名称(Using lambda expression to get property OR type name)

我可能会误解,但直接x => x将是一个ParameterExpression 。 只需在现有is MemberExpression测试下添加一个额外的测试: if (expression is MemberExpression) { // As-is } // New condition if (expression is ParameterExpression) { return expression.Type.Name; } 使用此代码: class Car { publi...

从类型lambda表达式中获取所有属性表达式(Get all property expressions from a type lambda expressions)

您可以在表达式上使用反射 foreach (var p in stage.GetType().GetProperties()) { } 但是,如果你这样做可能会有相当大的性能损失,而且它可以打开一整套安全蠕虫,特别是如果你使用你的类来访问数据库。 但是,您可以扩展这个想法,并定义一些属性来标记隐藏的字段,并使用您的扩展方法来挑选它们。 You can use reflection on expression foreach (va...

使用该lambda中包含的匿名类型定义lambda表达式(Defining a lambda expression with an anonymous type contained within that lambda)

你有什么理由不想将lambda表达式直接放在GroupBy调用中吗? 这就是它通常挂在一起的方式: var groupedData = myDataCollection.GroupBy(md => new { md.Property1, md.Property2, md.Pro...

使用内部委托类型编译lambda表达式(Compile lambda expression with internal delegate type)

F#和C#使用不同的策略为委托发出Invoke方法。 如果您尝试在C#中定义类似的委托 - 委托类型将是内部但具有公共Invoke方法。 F#定义了与声明类型具有相同可见性的Invoke方法。 当Expression.Lambda中的代码尝试在给定的委托类型中查找Invoke方法时,它只查找公共方法,假设所有编译器的行为与C#类似 F# and C# use different strategies for emitting Invoke method for delegates. If you ...

如何使用lambda表达式和匿名类型获取类型的属性名称?(How do I get property names of a type using a lambda expression and anonymous type?)

我很懒,所以这段代码只处理公共属性。 但它应该是一个很好的基础,让你开始。 public static string[] Foo<T>(Expression<Func<T, object>> func) { var properties = func.Body.Type.GetProperties(); return typeof(T).GetProperties() .Where(p => properties.Any(x => p.Name == x.Name...

lambda表达式的扩展方法(Extension method on lambda expression)

你不能这样做,因为lambda表达式本身没有类型; 它的类型由上下文决定(例如,如果将其分配给委托变量或将其作为参数传递给方法)。 由于((Thing t) => t.Property)没有类型,因此您无法在其上调用扩展方法,因为编译器不知道哪些扩展方法是有效候选。 但是,您可以声明一个变量并在其上调用扩展方法: Func<Thing, OtherThing> func = t => t.Property; string name = func.GetName(); You can't do t...

相关文章

更多

[Netty 1] 初识Netty

1. 简介 最早接触netty是在阅读Zookeeper源码的时候,后来看到Storm的消息传输层也由 ...

Netty环境配置

netty是一个java事件驱动的网络通信框架,也就是一个jar包,只要在项目里引用即可。

Netty开发环境配置

最新版本的Netty 4.x和JDK 1.6及更高版本

Netty源码分析

Netty提供异步的、事件驱动的网络应用程序框架和工具,用以快速开发高性能、高可靠性的网络服务器和客户 ...

storm学习之Netty代替ZMQ

整理自 http://www.csdn.net/article/2014-08-04/2821018/ ...

Netty基于流的传输处理

​在TCP/IP的基于流的传输中,接收的数据被存储到套接字接收缓冲器中。不幸的是,基于流的传输的缓冲器 ...

Netty入门实例-时间服务器

Netty中服务器和客户端之间最大的和唯一的区别是使用了不同的Bootstrap和Channel实现

Netty入门实例-使用POJO代替ByteBuf

使用TIME协议的客户端和服务器示例,让它们使用POJO来代替原来的ByteBuf。

在Twitter,Netty 4 GC开销降为五分之一

原文:http://www.infoq.com/cn/news/2013/11/netty4-twit ...

Netty入门实例-编写服务器端程序

channelRead()处理程序方法实现如下

最新问答

更多

获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)

我用Google搜索了一个解决方案。 “EnumDisplayModeProvider”是我自己设置网站的各种模式的枚举。 public EnumDisplayModeProvider GetDisplayModeId() { foreach (var mode in DisplayModeProvider.Instance.Modes) if (mode.CanHandleContext(HttpContext)) {

如何通过引用返回对象?(How is returning an object by reference possible?)

这相对简单:在类的构造函数中,您可以分配内存,例如使用new 。 如果你制作一个对象的副本,你不是每次都分配新的内存,而是只复制指向原始内存块的指针,同时递增一个也存储在内存中的引用计数器,使得每个副本都是对象可以访问它。 如果引用计数降至零,则销毁对象将减少引用计数并仅释放分配的内存。 您只需要一个自定义复制构造函数和赋值运算符。 这基本上是共享指针的工作方式。 This is relatively easy: In the class' constructor, you allocate m

矩阵如何存储在内存中?(How are matrices stored in memory?)

正如它在“熵编码”中所说的那样,使用Z字形图案,与RLE一起使用,在许多情况下,RLE已经减小了尺寸。 但是,据我所知,DCT本身并没有给出稀疏矩阵。 但它通常会增强矩阵的熵。 这是compressen变得有损的点:输入矩阵用DCT传输,然后量化量化然后使用霍夫曼编码。 As it says in "Entropy coding" a zig-zag pattern is used, together with RLE which will already reduce size for man

每个请求的Java新会话?(Java New Session For Each Request?)

你是如何进行重定向的? 您是否事先调用了HttpServletResponse.encodeRedirectURL()? 在这里阅读javadoc 您可以使用它像response.sendRedirect(response.encodeRedirectURL(path)); The issue was with the path in the JSESSIONID cookie. I still can't figure out why it was being set to the tomca

css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)

我认为word-break ,如果你想在一个单词中打破行,你可以指定它,这样做可以解决问题: .column { word-break:break-all; } jsFiddle演示。 您可以在此处阅读有关word-break属性的更多信息。 I think word-break, with which you can specify if you want to break line within a word, will do the trick: .column { word-break

无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)

我认为您忘记在分类时间内缩放输入图像,如train_test.prototxt文件的第11行所示。 您可能应该在C ++代码中的某个位置乘以该因子,或者使用Caffe图层来缩放输入(请查看ELTWISE或POWER图层)。 编辑: 在评论中进行了一次对话之后,结果发现在classification.cpp文件中错误地删除了图像均值,而在原始训练/测试管道中没有减去图像均值。 I think you have forgotten to scale the input image during cl

xcode语法颜色编码解释?(xcode syntax color coding explained?)

转到: Xcode => Preferences => Fonts & Colors 您将看到每个语法高亮颜色旁边都有一个简短的解释。 Go to: Xcode => Preferences => Fonts & Colors You'll see that each syntax highlighting colour has a brief explanation next to it.

在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)

你考虑过第三方拼写检查吗? 您可以将在C#中开发的自定义WinForms控件插入访问数据库吗? VB6控件怎么样? 如果你能找到一个使用第三方库进行拼写检查的控件,那可能会有效。 Have you considered a third party spell checker? Can you insert a custom WinForms controls developed in C# into an access database? What about a VB6 control? If

从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)

我有同样的问题,因为我在远程服务器上有两个图像,我需要在每天的预定义时间复制到我的本地服务器,这是我能够提出的代码... try { if(@copy('url/to/source/image.ext', 'local/absolute/path/on/server/' . date("d-m-Y") . ".gif")) { } else { $errors = error_get_last(); throw new Exception($err

从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))

我不确定我完全明白你在说什么。 你能编辑你的帖子并包含你正在做的Subversion命令/操作的特定顺序吗? 最好使用命令行svn客户端,以便容易为其他人重现问题。 如果您只是想获取文件的旧副本(即使该文件不再存在),您可以使用如下命令: svn copy ${repo}/trunk/moduleA/file1@${rev} ${repo}/trunk/moduleB/file1 其中${repo}是您的存储库的URL, ${rev}是您想要的文件的版本。 这将恢复该文件的旧版本,包括最高版本