SlideShare a Scribd company logo
1 of 70
Download to read offline
Groovyしたり
RPしなかったり
あとは時々
布教活動したり
G*ワークショップ
2013/09/20
13年9月25日水曜日
お前誰よ
•名前:杉浦孝博
•twitter:@touchez_du_bois
•自称「アニメエヴァンジェリスト」
•...まぁ、いつものとおり。
13年9月25日水曜日
さて、
13年9月25日水曜日
世の中には
13年9月25日水曜日
流行っているのか
わからないモノ
13年9月25日水曜日
というのも
ございまして。
13年9月25日水曜日
その中の一つ
13年9月25日水曜日
RP
13年9月25日水曜日
というのが
ございます。
13年9月25日水曜日
RP?
13年9月25日水曜日
Reactive
Programming
13年9月25日水曜日
Reactive
Programming?
13年9月25日水曜日
What s RP?
•データ(時間とともに変化する値)の
流れとその伝搬(振る舞い)の関係性
を記述することでプログラミングを
行うパラダイム。
13年9月25日水曜日
What s RP?
•データとして単なる値だけでなく、
入力ストリーム、イベント、時刻と
いったものも、時間とともに変化す
るデータとして同じように取り扱う
えるものと考える。
13年9月25日水曜日
G*的には...
•GParsの「Data Flow」な感じ。
import static groovyx.gpars.dataflow.Dataflow.task
final def x = new DataflowVariable()
final def y = new DataflowVariable()
final def z = new DataflowVariable()
task {
z << x.val + y.val
println "Result: ${z.val}"
}
task {
x << 10
}
task {
y << 5
}
13年9月25日水曜日
G*じゃない的には...
•Excelの「表計算」な感じ。
13年9月25日水曜日
詳しくは...
•http://www.reactivemanifesto.org/
13年9月25日水曜日
さて、
13年9月25日水曜日
R
P
の
話
は
こ
れ
く
ら
い
に
し
て
わ
か
ん
ね
ぇ
し
!
13年9月25日水曜日
※『やはり俺の青春ラブコメはまちがっている。』の平塚先生
13年9月25日水曜日
※プロレスラーの外道選手
13年9月25日水曜日
※プロレスラーの邪道選手
13年9月25日水曜日
※プロレスラーの非道選手
13年9月25日水曜日
※プロレスラーの故冬木弘道選手
13年9月25日水曜日
※プロレスラーのライオン道選手
13年9月25日水曜日
※現在WWEのクリス・ジェリコ選手
⇒
13年9月25日水曜日
そんなことは
さておき
13年9月25日水曜日
.NETでRP
•Rx(Reactive Extensions)
•http://rx.codeplex.com/
•Microsoft Open Technologies産
•JavaScript,C++,Ruby,Python用も
13年9月25日水曜日
JavaでRP
•それなりにライブラリが提供されて
いる。
•reactive4java
•Reactor
•RxJava
13年9月25日水曜日
reactive4java
•有志ベース(?)。
•ちょっと...な感じ。
•GWTとも連携。
•https://code.google.com/p/reactive4java/
13年9月25日水曜日
Reactor
•SpringSource産。
•多機能な感じ。
•Reactorを使ったデータアクセス用
のコンポーネントや、Grails用のイ
ベントプラグインもある。
•https://github.com/reactor/reactor/
13年9月25日水曜日
RxJava
•Netflix産。
•お手軽な感じ。
•RxJavaを使った分散システム用のラ
イブラリ(Hystrix)もある。
•https://github.com/Netflix/RxJava/
13年9月25日水曜日
RP with Groovy
•もともとがJavaベースであるため、
GroovyのClosureをそのままでは使
えない。
•メソッドの引数の型が合わず、「そ
んなメソッド知らんがな」と激おこ
プンプン丸。
13年9月25日水曜日
そこで...
•ReactorとRxJavaについては、
Groovy、というかGroovyの
Closureが使えるためのライブラリ
がある。
•RxJavaについては、Clojureと
Scalaもサポート。
13年9月25日水曜日
Modularization(m12n)
•GroovyのClosureを使えるようにす
るために、Groovy 2.0から導入され
た「モジュール化」の機能で実現し
ている。
13年9月25日水曜日
詳細は
•http://beta.mybetabook.com/showpage/
508402c90cf2ffb79bb046dd
13年9月25日水曜日
ただし...
•ReactorとRxJavaでは、アプローチ
の仕方、というか実現方法が異な
る。
13年9月25日水曜日
Reactorのアプローチ
•Closureを引数にとるオーバーロー
ドのメソッドを定義し、オリジナル
のクラスに追加する。
•Closureはラッパークラスで隠 。
•オーソドックスなアプローチ。
13年9月25日水曜日
RxJavaのアプローチ
•引数の型をオリジナルの型からClosure
に変換して実行する「MetaMethod」
を定義するExtensionModuleクラスを
作成する。
•Closureはラッパークラスで隠 。
•アバンギャルドなアプローチ。
13年9月25日水曜日
Reactorの例
// モジュール・ディスクリプタ
// META-INF/services/org.codehaus.groovy.runtime.ExtensionModule
moduleName=reactor-groovy-module
moduleVersion=1.0
extensionClasses=reactor.groovy.ext.ObservableExtensions,reactor.groo
vy.ext.LinkableExtensions,reactor.groovy.ext.ComposableExtensions,rea
ctor.groovy.ext.ProcessorExtensions
staticExtensionClasses=reactor.groovy.ext.ReactorStaticExtensions
13年9月25日水曜日
Reactorの例
// ヘルパークラス
class ObservableExtensions {
/**
* Closure converters
*/
static <T, E extends Event<T>, V> Registration<Consumer<E>>
receive(final reactor.core.Observable selfType,
final Selector key,
final Closure<V> closure) {
selfType.receive key, new ClosureEventFunction<E, V>(closure)
}
}
// オリジナルのクラス・インタフェース
public interface Observable {
<E extends Event<?>, V> Registration<Consumer<E>>
receive(Selector sel, Function<E, V> fn);
}
13年9月25日水曜日
RxJavaの例
// モジュール・ディスクリプタ
// META-INF/services/org.codehaus.groovy.runtime.ExtensionModule
moduleFactory=rx.lang.groovy.RxGroovyPropertiesModuleFactory
13年9月25日水曜日
RxJavaの例
// モジュール・ディスクリプタ
// org/codehaus/groovy/runtime/m12n/StandardPropertiesModuleFactory.java
public class StandardPropertiesModuleFactory extends PropertiesModuleFactory {
public final static String MODULE_FACTORY_KEY = "moduleFactory";
public ExtensionModule newModule(final Properties properties,
final ClassLoader classLoader) {
String factoryName = properties.getProperty(MODULE_FACTORY_KEY);
if (factoryName!=null) {
Class<? extends PropertiesModuleFactory> factoryClass =
(Class<? extends PropertiesModuleFactory>)
classLoader.loadClass(factoryName);
PropertiesModuleFactory delegate = factoryClass.newInstance();
return delegate.newModule(properties, classLoader);
}
return MetaInfExtensionModule.newModule(properties, classLoader);
}
}
13年9月25日水曜日
RxJavaの例
// モジュール・ディスクリプタ
// rx/lang/groovy/RxGroovyPropertiesModuleFactory.java
public class RxGroovyPropertiesModuleFactory
extends PropertiesModuleFactory {
@Override
public ExtensionModule newModule(
Properties properties,
ClassLoader classLoader) {
return new RxGroovyExtensionModule();
}
}
13年9月25日水曜日
RxJavaの例
// rx/lang/groovy/RxGroovyExtensionModule.java
public class RxGroovyExtensionModule extends ExtensionModule {
private final static Class[] CLASS_TO_EXTEND =
new Class[] { Observable.class, BlockingObservable.class };
@Override
public List<MetaMethod> getMetaMethods() {
List<MetaMethod> methods = new ArrayList<MetaMethod>();
for (Class classToExtend : CLASS_TO_EXTEND) {
for (final Method m : classToExtend.getMethods()) {
for (Class c : m.getParameterTypes()) {
if (Function.class.isAssignableFrom(c)) {
methods.add(createMetaMethod(m));
break;
}
}
}
}
return methods;
}
13年9月25日水曜日
RxJavaの例// rx/lang/groovy/RxGroovyExtensionModule.java
private MetaMethod createMetaMethod(final Method m) {
return new MetaMethod() {
@Override
public Object invoke(Object object, Object[] arguments) {
Object[] newArgs = new Object[arguments.length];
for (int i = 0; i < arguments.length; i++) {
final Object o = arguments[i];
if (o instanceof Closure) {
if (Action.class.isAssignableFrom(m.getParameterTypes()[i])) {
newArgs[i] = new GroovyActionWrapper((Closure) o);
} else
if(OnSubscribeFunc.class.isAssignableFrom(m.getParameterTypes()[i])) {
newArgs[i] = new GroovyOnSubscribeFuncWrapper((Closure) o);
} else {
newArgs[i] = new GroovyFunctionWrapper((Closure) o);
}
} else {
newArgs[i] = o;
}
}
return m.invoke(object, newArgs);
}
13年9月25日水曜日
Which アプローチ?
•Reactorのアプローチ
•長所:静的型チェック・静的コンパイ
ルと共存できる。
•短所:Closureを適用したいクラスを
使用するメソッドすべてにオーバーロ
ードする必要がある。
13年9月25日水曜日
Which アプローチ?
•RxJavaのアプローチ
•長所:対象のメソッドが増えても、コ
ードの修正不要or少ない。
•短所:静的型チェック・静的コンパイ
ルと共存できない。
13年9月25日水曜日
まとめ
13年9月25日水曜日
まとめ
•m12n(モジュール化)、ぱない。
•RPとGrailsやVert.xの組み合わせ
は、ぱない、気がしないでもない。
13年9月25日水曜日
さて、
13年9月25日水曜日
皆様の期待に
応えて
13年9月25日水曜日
いつもの
やりますか!
13年9月25日水曜日
7∼9月期の
おススメアニメ
13年9月25日水曜日
日常系で
癒やされたい
13年9月25日水曜日
13年9月25日水曜日
13年9月25日水曜日
求ム
家族愛
13年9月25日水曜日
13年9月25日水曜日
夜食テロに
襲撃されたい
13年9月25日水曜日
13年9月25日水曜日
13年9月25日水曜日
10∼12月期の
おススメ
13年9月25日水曜日
制作会社押し
13年9月25日水曜日
13年9月25日水曜日
『凪のあすから』
13年9月25日水曜日
ほっちゃん
(永遠の17歳)
のファン
13年9月25日水曜日
13年9月25日水曜日
『ミス・モノクローム』
13年9月25日水曜日
ご清聴ありがと
うございました
13年9月25日水曜日

More Related Content

Featured

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
ThinkNow
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Groovyしたり RPしなかったり あとは時々布教活動したり