模式匹配框架? [英] Pattern Matching framework?

查看:128
本文介绍了模式匹配框架?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将很快解决Java(GWT)项目(相关问题)。也许我试图在这里展开一些事情,但我想知道是否有任何用Java编写的模式匹配框架(不知道是否有这个术语)? (也许这是我长期接触Erlang时总是扭曲我对模式的想法: - )

我将使用消息传递体系结构在我的Java组件,我希望有效地将消息匹配到动作。



也许我应该坚持使用本地化的状态机还是还有其他的东西?



更新:消息将是一个携带仅数据的实例对象。我目前没有计划使用继承来传递语义到上述消息,而是简单的属性。



Update2 :在集体智慧之后所以(看请看这里),Scala似乎也超出了范围。



(注意:Java新手......请保持温和)

解决方案

您可能需要的是 Javaspaces (Java实现),并根据其属性匹配对象(在Javaspace世界中称为条目)。

空格存储具有特定属性或条目的对象(例如关联货币,城市,用户,等等)。然后,您可以通过指定0个或更多个这样的条目从空间中选择对象,从而取回0个或更多个对象。因此,它特别适用于消息传递和生产者/消费者场景。



因此,您可以将对象(消息)与特定属性(例如消息类型,类型等),您的消费者将根据一组0个或更多属性来选择这些对象。请注意,此需要修改您正在存储的基础对象。您可以在一个JVM中运行一个空间进程 - 它不仅仅是一个网络存储模式。


I will be tackling a Java (GWT) project soon (related question). Maybe I am trying to stretch things here but I was wondering if there is any "pattern matching framework" (don't really know if there is a term for this) written in Java? (maybe it is my prolonged exposure to Erlang that twists my thoughts around patterns all the time :-)

I will be using a "message passing" architecture to communicate between my Java components and I'd like to efficiently "match" messages to actions.

Maybe I should just stick with localized state-machines or is there anything else?

Updated: a "message" will be an instance-object carrying "data only". I am not currently planning on using inheritance for conveying semantics to the said messages but rather simple properties.

Update2: after taping the collective wisdom of SO (see here), it seems that Scala is out-of-scope also.

(NOTE: Java novice here... please be gentle)

解决方案

What you may be looking for are Javaspaces (a Java implementation of tuple-spaces) and matching objects based on their attributes (called 'entries' in the Javaspace world).

Spaces store objects with particular attributes or entries (e.g. an associated currency, city, user, whatever). You can then select objects from the space by specifying 0 or more such entries, and thus get back 0 or more objects. As such, it's a useful pattern for messaging and producer/consumer scenarios in particular.

So you can store your objects (messages) with particular attributes (e.g. message type, consumer type etc.) and your consumers will select these objects based on a set of 0 or more attributes. Note that this doesn't require modification of the underlying object that you're storing. You can run a space in-process (in one JVM) - it's not just a networked storage pattern.

这篇关于模式匹配框架?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆