Convert Narya (most of the way) over to a Maven Ant task based build. The
ActionScript bits remain belligerent, but the Java stuff is mostly shipshape. git-svn-id: svn+ssh://src.earth.threerings.net/narya/trunk@6222 542714f4-19e9-0310-aa3c-eee0fc999fb1
This commit is contained in:
@@ -1,111 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<flex-config>
|
||||
<compiler>
|
||||
<accessible>false</accessible>
|
||||
<allow-source-path-overlap>false</allow-source-path-overlap>
|
||||
<as3>true</as3>
|
||||
<source-path>
|
||||
<path-element>../src/as</path-element>
|
||||
</source-path>
|
||||
<library-path>
|
||||
<path-element>@flex_sdk_dir@/frameworks/libs</path-element>
|
||||
<path-element>../../dist/lib/ooolib.swc</path-element>
|
||||
<path-element>../../dist/lib/corelib.swc</path-element>
|
||||
<path-element>../../dist/lib/asunit.swc</path-element>
|
||||
</library-path>
|
||||
<external-library-path>
|
||||
<path-element>@flex_sdk_dir@/frameworks/libs/player/{targetPlayerMajorVersion}</path-element>
|
||||
</external-library-path>
|
||||
<locale>
|
||||
<locale-element>en_US</locale-element>
|
||||
</locale>
|
||||
<fonts>
|
||||
<advanced-anti-aliasing>true</advanced-anti-aliasing>
|
||||
<max-cached-fonts>20</max-cached-fonts>
|
||||
<max-glyphs-per-face>1000</max-glyphs-per-face>
|
||||
<managers>
|
||||
<manager-class>flash.fonts.JREFontManager</manager-class>
|
||||
<manager-class>flash.fonts.AFEFontManager</manager-class>
|
||||
<manager-class>flash.fonts.BatikFontManager</manager-class>
|
||||
</managers>
|
||||
<local-fonts-snapshot>@flex_sdk_dir@/frameworks/localFonts.ser</local-fonts-snapshot>
|
||||
</fonts>
|
||||
<namespaces>
|
||||
<namespace>
|
||||
<uri>http://www.adobe.com/2006/mxml</uri>
|
||||
<manifest>@flex_sdk_dir@/frameworks/mxml-manifest.xml</manifest>
|
||||
</namespace>
|
||||
</namespaces>
|
||||
<incremental>false</incremental>
|
||||
<optimize>true</optimize>
|
||||
<debug>true</debug>
|
||||
<show-actionscript-warnings>true</show-actionscript-warnings>
|
||||
<show-binding-warnings>true</show-binding-warnings>
|
||||
<show-shadowed-device-font-warnings>true</show-shadowed-device-font-warnings>
|
||||
<show-unused-type-selector-warnings>false</show-unused-type-selector-warnings>
|
||||
<strict>true</strict>
|
||||
<use-resource-bundle-metadata>true</use-resource-bundle-metadata>
|
||||
<verbose-stacktraces>true</verbose-stacktraces>
|
||||
<warn-array-tostring-changes>false</warn-array-tostring-changes>
|
||||
<warn-assignment-within-conditional>true</warn-assignment-within-conditional>
|
||||
<warn-bad-array-cast>true</warn-bad-array-cast>
|
||||
<warn-bad-bool-assignment>true</warn-bad-bool-assignment>
|
||||
<warn-bad-date-cast>true</warn-bad-date-cast>
|
||||
<warn-bad-es3-type-method>true</warn-bad-es3-type-method>
|
||||
<warn-bad-es3-type-prop>true</warn-bad-es3-type-prop>
|
||||
<warn-bad-nan-comparison>true</warn-bad-nan-comparison>
|
||||
<warn-bad-null-assignment>true</warn-bad-null-assignment>
|
||||
<warn-bad-null-comparison>true</warn-bad-null-comparison>
|
||||
<warn-bad-undefined-comparison>true</warn-bad-undefined-comparison>
|
||||
<warn-boolean-constructor-with-no-args>false</warn-boolean-constructor-with-no-args>
|
||||
<warn-changes-in-resolve>false</warn-changes-in-resolve>
|
||||
<warn-class-is-sealed>true</warn-class-is-sealed>
|
||||
<warn-const-not-initialized>true</warn-const-not-initialized>
|
||||
<warn-constructor-returns-value>false</warn-constructor-returns-value>
|
||||
<warn-deprecated-event-handler-error>true</warn-deprecated-event-handler-error>
|
||||
<warn-deprecated-function-error>true</warn-deprecated-function-error>
|
||||
<warn-deprecated-property-error>true</warn-deprecated-property-error>
|
||||
<warn-duplicate-argument-names>true</warn-duplicate-argument-names>
|
||||
<warn-duplicate-variable-def>true</warn-duplicate-variable-def>
|
||||
<warn-for-var-in-changes>false</warn-for-var-in-changes>
|
||||
<warn-import-hides-class>true</warn-import-hides-class>
|
||||
<warn-instance-of-changes>true</warn-instance-of-changes>
|
||||
<warn-internal-error>true</warn-internal-error>
|
||||
<warn-level-not-supported>true</warn-level-not-supported>
|
||||
<warn-missing-namespace-decl>true</warn-missing-namespace-decl>
|
||||
<warn-negative-uint-literal>true</warn-negative-uint-literal>
|
||||
<warn-no-constructor>false</warn-no-constructor>
|
||||
<warn-no-explicit-super-call-in-constructor>false</warn-no-explicit-super-call-in-constructor>
|
||||
<warn-no-type-decl>true</warn-no-type-decl>
|
||||
<warn-number-from-string-changes>false</warn-number-from-string-changes>
|
||||
<warn-scoping-change-in-this>false</warn-scoping-change-in-this>
|
||||
<warn-slow-text-field-addition>true</warn-slow-text-field-addition>
|
||||
<warn-unlikely-function-value>true</warn-unlikely-function-value>
|
||||
<warn-xml-class-has-changed>false</warn-xml-class-has-changed>
|
||||
</compiler>
|
||||
<default-background-color>0x000000</default-background-color>
|
||||
<default-frame-rate>30</default-frame-rate>
|
||||
<default-script-limits>
|
||||
<max-recursion-depth>1000</max-recursion-depth>
|
||||
<max-execution-time>15</max-execution-time>
|
||||
</default-script-limits>
|
||||
<default-size>
|
||||
<width>750</width>
|
||||
<height>700</height>
|
||||
</default-size>
|
||||
<metadata>
|
||||
<creator>Three Rings Design, Inc.</creator>
|
||||
<language>EN</language>
|
||||
<publisher>Three Rings Design, Inc.</publisher>
|
||||
</metadata>
|
||||
<runtime-shared-library-path>
|
||||
<path-element>@flex_sdk_dir@/frameworks/libs/framework.swc</path-element>
|
||||
<rsl-url>framework_3.2.0.3958.swz</rsl-url>
|
||||
<policy-file-url></policy-file-url>
|
||||
<rsl-url>framework_3.2.0.3958.swf</rsl-url>
|
||||
<policy-file-url></policy-file-url>
|
||||
</runtime-shared-library-path>
|
||||
<static-link-runtime-shared-libraries>true</static-link-runtime-shared-libraries>
|
||||
<target-player>10.0.0</target-player>
|
||||
<use-network>true</use-network>
|
||||
</flex-config>
|
||||
@@ -1,366 +0,0 @@
|
||||
<flex-config>
|
||||
<!-- benchmark: output performance benchmark-->
|
||||
<!-- benchmark usage:
|
||||
<benchmark>boolean</benchmark>
|
||||
-->
|
||||
<compiler>
|
||||
<!-- compiler.accessible: generate an accessible SWF-->
|
||||
<accessible>false</accessible>
|
||||
<!-- compiler.actionscript-file-encoding: specifies actionscript file encoding. If there is no BOM in the AS3 source files, the compiler will use this file encoding.-->
|
||||
<!-- compiler.actionscript-file-encoding usage:
|
||||
<actionscript-file-encoding>string</actionscript-file-encoding>
|
||||
-->
|
||||
<!-- compiler.allow-source-path-overlap: checks if a source-path entry is a subdirectory of another source-path entry. It helps make the package names of MXML components unambiguous.-->
|
||||
<allow-source-path-overlap>false</allow-source-path-overlap>
|
||||
<!-- compiler.as3: use the ActionScript 3 class based object model for greater performance and better error reporting. In the class based object model most built-in functions are implemented as fixed methods of classes.-->
|
||||
<as3>true</as3>
|
||||
<!-- compiler.context-root: path to replace {context.root} tokens for service channel endpoints-->
|
||||
<!-- compiler.context-root usage:
|
||||
<context-root>context-path</context-root>
|
||||
-->
|
||||
<!-- compiler.debug: generates a movie that is suitable for debugging-->
|
||||
<debug>false</debug>
|
||||
<!-- compiler.defaults-css-files usage:
|
||||
<defaults-css-files>
|
||||
<filename>string</filename>
|
||||
<filename>string</filename>
|
||||
</defaults-css-files>
|
||||
-->
|
||||
<!-- compiler.defaults-css-url: defines the location of the default style sheet. Setting this option overrides the implicit use of the defaults.css style sheet in the framework.swc file.-->
|
||||
<!-- compiler.defaults-css-url usage:
|
||||
<defaults-css-url>string</defaults-css-url>
|
||||
-->
|
||||
<!-- compiler.define: define a global AS3 conditional compilation definition, e.g. -define=CONFIG::debugging,true or -define+=CONFIG::debugging,true (to append to existing definitions in flex-config.xml) -->
|
||||
<!-- compiler.define usage:
|
||||
<define>
|
||||
<name>string</name>
|
||||
<value>string</value>
|
||||
<value>string</value>
|
||||
</define>
|
||||
-->
|
||||
<!-- compiler.es: use the ECMAScript edition 3 prototype based object model to allow dynamic overriding of prototype properties. In the prototype based object model built-in functions are implemented as dynamic properties of prototype objects.-->
|
||||
<es>false</es>
|
||||
<!-- compiler.external-library-path: list of SWC files or directories to compile against but to omit from linking-->
|
||||
<external-library-path>
|
||||
</external-library-path>
|
||||
<fonts>
|
||||
<!-- compiler.fonts.advanced-anti-aliasing: enables advanced anti-aliasing for embedded fonts, which provides greater clarity for small fonts.-->
|
||||
<advanced-anti-aliasing>true</advanced-anti-aliasing>
|
||||
<!-- compiler.fonts.flash-type: enables FlashType for embedded fonts, which provides greater clarity for small fonts.-->
|
||||
<!-- compiler.fonts.flash-type usage:
|
||||
<flash-type>boolean</flash-type>
|
||||
-->
|
||||
<languages>
|
||||
<!-- compiler.fonts.languages.language-range: a range to restrict the number of font glyphs embedded into the SWF-->
|
||||
<!-- compiler.fonts.languages.language-range usage:
|
||||
<language-range>
|
||||
<lang>string</lang>
|
||||
<range>string</range>
|
||||
<range>string</range>
|
||||
</language-range>
|
||||
-->
|
||||
</languages>
|
||||
<!-- compiler.fonts.local-fonts-snapshot: File containing system font data produced by flex2.tools.FontSnapshot.-->
|
||||
<local-fonts-snapshot>@flex_sdk_dir@/frameworks/localFonts.ser</local-fonts-snapshot>
|
||||
<!-- compiler.fonts.managers: Compiler font manager classes, in policy resolution order-->
|
||||
<managers>
|
||||
<manager-class>flash.fonts.JREFontManager</manager-class>
|
||||
<manager-class>flash.fonts.AFEFontManager</manager-class>
|
||||
<manager-class>flash.fonts.BatikFontManager</manager-class>
|
||||
</managers>
|
||||
<!-- compiler.fonts.max-cached-fonts: sets the maximum number of fonts to keep in the server cache. The default value is 20.-->
|
||||
<max-cached-fonts>20</max-cached-fonts>
|
||||
<!-- compiler.fonts.max-glyphs-per-face: sets the maximum number of character glyph-outlines to keep in the server cache for each font face. The default value is 1000.-->
|
||||
<max-glyphs-per-face>1000</max-glyphs-per-face>
|
||||
</fonts>
|
||||
<!-- compiler.headless-server: a flag to set when Flex is running on a server without a display-->
|
||||
<!-- compiler.headless-server usage:
|
||||
<headless-server>boolean</headless-server>
|
||||
-->
|
||||
<!-- compiler.include-libraries: a list of libraries (SWCs) to completely include in the SWF-->
|
||||
<!-- compiler.include-libraries usage:
|
||||
<include-libraries>
|
||||
<library>string</library>
|
||||
<library>string</library>
|
||||
</include-libraries>
|
||||
-->
|
||||
<!-- compiler.incremental: enables incremental compilation-->
|
||||
<!-- compiler.incremental usage:
|
||||
<incremental>boolean</incremental>
|
||||
-->
|
||||
<!-- compiler.keep-all-type-selectors: disables the pruning of unused CSS type selectors-->
|
||||
<!-- compiler.keep-all-type-selectors usage:
|
||||
<keep-all-type-selectors>boolean</keep-all-type-selectors>
|
||||
-->
|
||||
<!-- compiler.keep-as3-metadata: keep the specified metadata in the SWF-->
|
||||
<!-- compiler.keep-as3-metadata usage:
|
||||
<keep-as3-metadata>
|
||||
<name>string</name>
|
||||
<name>string</name>
|
||||
</keep-as3-metadata>
|
||||
-->
|
||||
<!-- compiler.keep-generated-actionscript: save temporary source files generated during MXML compilation-->
|
||||
<keep-generated-actionscript>false</keep-generated-actionscript>
|
||||
<!-- compiler.library-path: list of SWC files or directories that contain SWC files-->
|
||||
<library-path>
|
||||
</library-path>
|
||||
<!-- compiler.locale: specifies the locale for internationalization-->
|
||||
<locale>
|
||||
<locale-element>en_US</locale-element>
|
||||
</locale>
|
||||
<mxml>
|
||||
<!-- compiler.mxml.compatibility-version: specifies a compatibility version. e.g. -compatibility-version=2.0.1-->
|
||||
<!-- compiler.mxml.compatibility-version usage:
|
||||
<compatibility-version>version</compatibility-version>
|
||||
-->
|
||||
</mxml>
|
||||
<namespaces>
|
||||
<!-- compiler.namespaces.namespace: Specify a URI to associate with a manifest of components for use as MXML elements-->
|
||||
<namespace>
|
||||
<uri>http://www.adobe.com/2006/mxml</uri>
|
||||
<manifest>@flex_sdk_dir@/frameworks/mxml-manifest.xml</manifest>
|
||||
</namespace>
|
||||
</namespaces>
|
||||
<!-- compiler.optimize: Enable post-link SWF optimization-->
|
||||
<optimize>true</optimize>
|
||||
<!-- compiler.services: path to Flex Data Services configuration file-->
|
||||
<!-- compiler.services usage:
|
||||
<services>filename</services>
|
||||
-->
|
||||
<!-- compiler.show-actionscript-warnings: runs the AS3 compiler in a mode that detects legal but potentially incorrect code-->
|
||||
<show-actionscript-warnings>true</show-actionscript-warnings>
|
||||
<!-- compiler.show-binding-warnings: toggle whether warnings generated from data binding code are displayed-->
|
||||
<show-binding-warnings>true</show-binding-warnings>
|
||||
<!-- compiler.show-shadowed-device-font-warnings: toggles whether warnings are displayed when an embedded font name shadows a device font name-->
|
||||
<show-shadowed-device-font-warnings>true</show-shadowed-device-font-warnings>
|
||||
<!-- compiler.show-unused-type-selector-warnings: toggle whether warnings generated from unused CSS type selectors are displayed-->
|
||||
<show-unused-type-selector-warnings>true</show-unused-type-selector-warnings>
|
||||
<!-- compiler.source-path: list of path elements that form the roots of ActionScript class hierarchies-->
|
||||
<!-- compiler.source-path usage:
|
||||
<source-path>
|
||||
<path-element>string</path-element>
|
||||
<path-element>string</path-element>
|
||||
</source-path>
|
||||
-->
|
||||
<!-- compiler.strict: runs the AS3 compiler in strict error checking mode.-->
|
||||
<strict>true</strict>
|
||||
<!-- compiler.theme: list of CSS or SWC files to apply as a theme-->
|
||||
<!-- compiler.theme usage:
|
||||
<theme>
|
||||
<filename>string</filename>
|
||||
<filename>string</filename>
|
||||
</theme>
|
||||
-->
|
||||
<!-- compiler.use-resource-bundle-metadata: determines whether resources bundles are included in the application.-->
|
||||
<use-resource-bundle-metadata>true</use-resource-bundle-metadata>
|
||||
<!-- compiler.verbose-stacktraces: save callstack information to the SWF for debugging-->
|
||||
<verbose-stacktraces>true</verbose-stacktraces>
|
||||
<!-- compiler.warn-array-tostring-changes: Array.toString() format has changed.-->
|
||||
<warn-array-tostring-changes>false</warn-array-tostring-changes>
|
||||
<!-- compiler.warn-assignment-within-conditional: Assignment within conditional.-->
|
||||
<warn-assignment-within-conditional>true</warn-assignment-within-conditional>
|
||||
<!-- compiler.warn-bad-array-cast: Possibly invalid Array cast operation.-->
|
||||
<warn-bad-array-cast>true</warn-bad-array-cast>
|
||||
<!-- compiler.warn-bad-bool-assignment: Non-Boolean value used where a Boolean value was expected.-->
|
||||
<warn-bad-bool-assignment>true</warn-bad-bool-assignment>
|
||||
<!-- compiler.warn-bad-date-cast: Invalid Date cast operation.-->
|
||||
<warn-bad-date-cast>true</warn-bad-date-cast>
|
||||
<!-- compiler.warn-bad-es3-type-method: Unknown method.-->
|
||||
<warn-bad-es3-type-method>true</warn-bad-es3-type-method>
|
||||
<!-- compiler.warn-bad-es3-type-prop: Unknown property.-->
|
||||
<warn-bad-es3-type-prop>true</warn-bad-es3-type-prop>
|
||||
<!-- compiler.warn-bad-nan-comparison: Illogical comparison with NaN. Any comparison operation involving NaN will evaluate to false because NaN != NaN.-->
|
||||
<warn-bad-nan-comparison>true</warn-bad-nan-comparison>
|
||||
<!-- compiler.warn-bad-null-assignment: Impossible assignment to null.-->
|
||||
<warn-bad-null-assignment>true</warn-bad-null-assignment>
|
||||
<!-- compiler.warn-bad-null-comparison: Illogical comparison with null.-->
|
||||
<warn-bad-null-comparison>true</warn-bad-null-comparison>
|
||||
<!-- compiler.warn-bad-undefined-comparison: Illogical comparison with undefined. Only untyped variables (or variables of type *) can be undefined.-->
|
||||
<warn-bad-undefined-comparison>true</warn-bad-undefined-comparison>
|
||||
<!-- compiler.warn-boolean-constructor-with-no-args: Boolean() with no arguments returns false in ActionScript 3.0. Boolean() returned undefined in ActionScript 2.0.-->
|
||||
<warn-boolean-constructor-with-no-args>false</warn-boolean-constructor-with-no-args>
|
||||
<!-- compiler.warn-changes-in-resolve: __resolve is no longer supported.-->
|
||||
<warn-changes-in-resolve>false</warn-changes-in-resolve>
|
||||
<!-- compiler.warn-class-is-sealed: Class is sealed. It cannot have members added to it dynamically.-->
|
||||
<warn-class-is-sealed>true</warn-class-is-sealed>
|
||||
<!-- compiler.warn-const-not-initialized: Constant not initialized.-->
|
||||
<warn-const-not-initialized>true</warn-const-not-initialized>
|
||||
<!-- compiler.warn-constructor-returns-value: Function used in new expression returns a value. Result will be what the function returns, rather than a new instance of that function.-->
|
||||
<warn-constructor-returns-value>false</warn-constructor-returns-value>
|
||||
<!-- compiler.warn-deprecated-event-handler-error: EventHandler was not added as a listener.-->
|
||||
<warn-deprecated-event-handler-error>true</warn-deprecated-event-handler-error>
|
||||
<!-- compiler.warn-deprecated-function-error: Unsupported ActionScript 2.0 function.-->
|
||||
<warn-deprecated-function-error>true</warn-deprecated-function-error>
|
||||
<!-- compiler.warn-deprecated-property-error: Unsupported ActionScript 2.0 property.-->
|
||||
<warn-deprecated-property-error>true</warn-deprecated-property-error>
|
||||
<!-- compiler.warn-duplicate-argument-names: More than one argument by the same name.-->
|
||||
<warn-duplicate-argument-names>true</warn-duplicate-argument-names>
|
||||
<!-- compiler.warn-duplicate-variable-def: Duplicate variable definition -->
|
||||
<warn-duplicate-variable-def>true</warn-duplicate-variable-def>
|
||||
<!-- compiler.warn-for-var-in-changes: ActionScript 3.0 iterates over an object's properties within a "for x in target" statement in random order.-->
|
||||
<warn-for-var-in-changes>false</warn-for-var-in-changes>
|
||||
<!-- compiler.warn-import-hides-class: Importing a package by the same name as the current class will hide that class identifier in this scope.-->
|
||||
<warn-import-hides-class>true</warn-import-hides-class>
|
||||
<!-- compiler.warn-instance-of-changes: Use of the instanceof operator.-->
|
||||
<warn-instance-of-changes>true</warn-instance-of-changes>
|
||||
<!-- compiler.warn-internal-error: Internal error in compiler.-->
|
||||
<warn-internal-error>true</warn-internal-error>
|
||||
<!-- compiler.warn-level-not-supported: _level is no longer supported. For more information, see the flash.display package.-->
|
||||
<warn-level-not-supported>true</warn-level-not-supported>
|
||||
<!-- compiler.warn-missing-namespace-decl: Missing namespace declaration (e.g. variable is not defined to be public, private, etc.).-->
|
||||
<warn-missing-namespace-decl>true</warn-missing-namespace-decl>
|
||||
<!-- compiler.warn-negative-uint-literal: Negative value will become a large positive value when assigned to a uint data type.-->
|
||||
<warn-negative-uint-literal>true</warn-negative-uint-literal>
|
||||
<!-- compiler.warn-no-constructor: Missing constructor.-->
|
||||
<warn-no-constructor>false</warn-no-constructor>
|
||||
<!-- compiler.warn-no-explicit-super-call-in-constructor: The super() statement was not called within the constructor.-->
|
||||
<warn-no-explicit-super-call-in-constructor>false</warn-no-explicit-super-call-in-constructor>
|
||||
<!-- compiler.warn-no-type-decl: Missing type declaration.-->
|
||||
<warn-no-type-decl>true</warn-no-type-decl>
|
||||
<!-- compiler.warn-number-from-string-changes: In ActionScript 3.0, white space is ignored and '' returns 0. Number() returns NaN in ActionScript 2.0 when the parameter is '' or contains white space.-->
|
||||
<warn-number-from-string-changes>false</warn-number-from-string-changes>
|
||||
<!-- compiler.warn-scoping-change-in-this: Change in scoping for the this keyword. Class methods extracted from an instance of a class will always resolve this back to that instance. In ActionScript 2.0 this is looked up dynamically based on where the method is invoked from.-->
|
||||
<warn-scoping-change-in-this>false</warn-scoping-change-in-this>
|
||||
<!-- compiler.warn-slow-text-field-addition: Inefficient use of += on a TextField.-->
|
||||
<warn-slow-text-field-addition>true</warn-slow-text-field-addition>
|
||||
<!-- compiler.warn-unlikely-function-value: Possible missing parentheses.-->
|
||||
<warn-unlikely-function-value>true</warn-unlikely-function-value>
|
||||
<!-- compiler.warn-xml-class-has-changed: Possible usage of the ActionScript 2.0 XML class.-->
|
||||
<warn-xml-class-has-changed>false</warn-xml-class-has-changed>
|
||||
</compiler>
|
||||
<!-- debug-password: the password to include in debuggable SWFs-->
|
||||
<debug-password></debug-password>
|
||||
<!-- default-background-color: default background color (may be overridden by the application code)-->
|
||||
<default-background-color>0x869CA7</default-background-color>
|
||||
<!-- default-frame-rate: default frame rate to be used in the SWF.-->
|
||||
<default-frame-rate>30</default-frame-rate>
|
||||
<!-- default-script-limits: default script execution limits (may be overridden by root attributes)-->
|
||||
<default-script-limits>
|
||||
<max-recursion-depth>1000</max-recursion-depth>
|
||||
<max-execution-time>15</max-execution-time>
|
||||
</default-script-limits>
|
||||
<!-- default-size: default application size (may be overridden by root attributes in the application)-->
|
||||
<default-size>
|
||||
<width>500</width>
|
||||
<height>375</height>
|
||||
</default-size>
|
||||
<!-- externs: a list of symbols to omit from linking when building a SWF-->
|
||||
<!-- externs usage:
|
||||
<externs>
|
||||
<symbol>string</symbol>
|
||||
<symbol>string</symbol>
|
||||
</externs>
|
||||
-->
|
||||
<frames>
|
||||
<!-- frames.frame: A SWF frame label with a sequence of classnames that will be linked onto the frame.-->
|
||||
<!-- frames.frame usage:
|
||||
<frame>
|
||||
<label>string</label>
|
||||
<classname>string</classname>
|
||||
</frame>
|
||||
-->
|
||||
</frames>
|
||||
<!-- include-resource-bundles: a list of resource bundles to include in the output SWC-->
|
||||
<!-- include-resource-bundles usage:
|
||||
<include-resource-bundles>
|
||||
<bundle>string</bundle>
|
||||
<bundle>string</bundle>
|
||||
</include-resource-bundles>
|
||||
-->
|
||||
<!-- includes: a list of symbols to always link in when building a SWF-->
|
||||
<!-- includes usage:
|
||||
<includes>
|
||||
<symbol>string</symbol>
|
||||
<symbol>string</symbol>
|
||||
</includes>
|
||||
-->
|
||||
<!-- link-report: Output a XML-formatted report of all definitions linked into the application.-->
|
||||
<!-- link-report usage:
|
||||
<link-report>filename</link-report>
|
||||
-->
|
||||
<!-- load-config: load a file containing configuration options-->
|
||||
<!--
|
||||
<load-config>${flexlib}/${configname}-config.xml</load-config>
|
||||
-->
|
||||
<!-- load-externs: an XML file containing <def>, <pre>, and <ext> symbols to omit from linking when building a SWF-->
|
||||
<!-- load-externs usage:
|
||||
<load-externs>filename</load-externs>
|
||||
-->
|
||||
<metadata>
|
||||
<!-- metadata.contributor: A contributor's name to store in the SWF metadata-->
|
||||
<!-- metadata.contributor usage:
|
||||
<contributor>name</contributor>
|
||||
-->
|
||||
<!-- metadata.creator: A creator's name to store in the SWF metadata-->
|
||||
<creator>Three Rings Design, Inc.</creator>
|
||||
<!-- metadata.date: The creation date to store in the SWF metadata-->
|
||||
<!-- metadata.date usage:
|
||||
<date>text</date>
|
||||
-->
|
||||
<!-- metadata.description: The default description to store in the SWF metadata-->
|
||||
<description>http://www.whirled.com</description>
|
||||
<!-- metadata.language: The language to store in the SWF metadata (i.e. EN, FR)-->
|
||||
<language>EN</language>
|
||||
<!-- metadata.localized-description: A localized RDF/XMP description to store in the SWF metadata-->
|
||||
<!-- metadata.localized-description usage:
|
||||
<localized-description>
|
||||
<text>string</text>
|
||||
<lang>string</lang>
|
||||
<lang>string</lang>
|
||||
</localized-description>
|
||||
-->
|
||||
<!-- metadata.localized-title: A localized RDF/XMP title to store in the SWF metadata-->
|
||||
<!-- metadata.localized-title usage:
|
||||
<localized-title>
|
||||
<title>string</title>
|
||||
<lang>string</lang>
|
||||
<lang>string</lang>
|
||||
</localized-title>
|
||||
-->
|
||||
<!-- metadata.publisher: A publisher's name to store in the SWF metadata-->
|
||||
<publisher>Three Rings Design, Inc.</publisher>
|
||||
<!-- metadata.title: The default title to store in the SWF metadata-->
|
||||
<title>Whirled</title>
|
||||
</metadata>
|
||||
<!-- output: the filename of the SWF movie to create-->
|
||||
<!-- output usage:
|
||||
<output>filename</output>
|
||||
-->
|
||||
<!-- raw-metadata: XML text to store in the SWF metadata (overrides metadata.* configuration)-->
|
||||
<!-- raw-metadata usage:
|
||||
<raw-metadata>text</raw-metadata>
|
||||
-->
|
||||
<!-- resource-bundle-list: prints a list of resource bundles to a file for input to the compc compiler to create a resource bundle SWC file. -->
|
||||
<!-- resource-bundle-list usage:
|
||||
<resource-bundle-list>filename</resource-bundle-list>
|
||||
-->
|
||||
<!-- runtime-shared-libraries: a list of runtime shared library URLs to be loaded before the application starts-->
|
||||
<!-- runtime-shared-libraries usage:
|
||||
<runtime-shared-libraries>
|
||||
<url>string</url>
|
||||
<url>string</url>
|
||||
</runtime-shared-libraries>
|
||||
-->
|
||||
<runtime-shared-library-path>
|
||||
</runtime-shared-library-path>
|
||||
<!-- static-link-runtime-shared-libraries: statically link the libraries specified by the -runtime-shared-libraries-path option.-->
|
||||
<static-link-runtime-shared-libraries>true</static-link-runtime-shared-libraries>
|
||||
<!-- target-player: specifies the version of the player the application is targeting. Features requiring a later version will not be compiled into the application. The minimum value supported is "9.0.0".-->
|
||||
<!-- target-player usage:
|
||||
<target-player>version</target-player>
|
||||
-->
|
||||
<!-- use-network: toggle whether the SWF is flagged for access to network resources-->
|
||||
<use-network>true</use-network>
|
||||
<!-- verify-digests: verifies the libraries loaded at runtime are the correct ones.-->
|
||||
<!-- verify-digests usage:
|
||||
<verify-digests>boolean</verify-digests>
|
||||
-->
|
||||
<!-- version: display the build version of the program-->
|
||||
<!-- version usage:
|
||||
<version>boolean</version>
|
||||
-->
|
||||
<!-- warnings: toggle the display of warnings-->
|
||||
<!-- warnings usage:
|
||||
<warnings>boolean</warnings>
|
||||
-->
|
||||
</flex-config>
|
||||
@@ -1,9 +0,0 @@
|
||||
#
|
||||
# $Id$
|
||||
#
|
||||
# Configuration for the Presents test server
|
||||
|
||||
# These invocation service providers will be registered with the
|
||||
# invocation manager during the server init process
|
||||
providers = \
|
||||
test = com.threerings.presents.server.TestProvider
|
||||
@@ -1,15 +0,0 @@
|
||||
#
|
||||
# $Id$
|
||||
#
|
||||
# Test localization properties file
|
||||
|
||||
m.foo = Foo arg one is '{0}' and two is '{1}'.
|
||||
m.biff = Biff arg one is '{0}' and two is '{1}'.
|
||||
m.meta = Meta arg one is '{0}' and two is '{1}'.
|
||||
|
||||
m.sheep = Don't suffix me
|
||||
m.sheep.0 = No sheep
|
||||
m.sheep.1 = One sheep
|
||||
m.sheep.n = {0} sheeps
|
||||
|
||||
m.coord = {0}x{1}
|
||||
@@ -1,92 +0,0 @@
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
// Narya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2010 Three Rings Design, Inc., All Rights Reserved
|
||||
// http://www.threerings.net/code/narya/
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it
|
||||
// under the terms of the GNU Lesser General Public License as published
|
||||
// by the Free Software Foundation; either version 2.1 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package com.threerings.bureau.client;
|
||||
|
||||
import com.samskivert.util.BasicRunQueue;
|
||||
import com.samskivert.util.OneLineLogFormatter;
|
||||
import com.samskivert.util.StringUtil;
|
||||
|
||||
import com.threerings.bureau.data.AgentObject;
|
||||
|
||||
import static com.threerings.bureau.Log.log;
|
||||
|
||||
/**
|
||||
* Extends bureau client minimally and provides a static main function to create a client and
|
||||
* connect to a server given by system properties.
|
||||
*/
|
||||
public class TestClient extends BureauClient
|
||||
{
|
||||
public static void main (String[] args)
|
||||
throws java.net.MalformedURLException
|
||||
{
|
||||
// make log pretty
|
||||
OneLineLogFormatter.configureDefaultHandler();
|
||||
|
||||
// create the client and log on
|
||||
TestClient client = new TestClient(
|
||||
System.getProperty("token"),
|
||||
System.getProperty("bureauId"));
|
||||
client.setServer(
|
||||
System.getProperty("serverName"),
|
||||
new int[] {Integer.parseInt(System.getProperty("serverPort"))});
|
||||
client.logon();
|
||||
|
||||
// run it
|
||||
((BasicRunQueue)client.getRunQueue()).run();
|
||||
}
|
||||
|
||||
/**
|
||||
* The agent class used by our director. Does not actually load any code, just logs the
|
||||
* start/stop requests.
|
||||
*/
|
||||
protected static class TestAgent extends Agent
|
||||
{
|
||||
@Override public void start () {
|
||||
log.info("Starting agent " + StringUtil.toString(_agentObj));
|
||||
}
|
||||
|
||||
@Override public void stop () {
|
||||
log.info("Stopping agent " + StringUtil.toString(_agentObj));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new test client.
|
||||
*/
|
||||
protected TestClient (String token, String bureauId)
|
||||
{
|
||||
super(token, bureauId, new BasicRunQueue());
|
||||
}
|
||||
|
||||
// overridden - creates a simple director
|
||||
@Override
|
||||
protected BureauDirector createDirector ()
|
||||
{
|
||||
// just use our test agent exclusively - in the real world, the agent created would depend
|
||||
// on the object's type and/or properties
|
||||
return new BureauDirector(_ctx) {
|
||||
@Override public Agent createAgent (AgentObject agentObj) {
|
||||
return new TestAgent();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,307 +0,0 @@
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
// Narya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2010 Three Rings Design, Inc., All Rights Reserved
|
||||
// http://www.threerings.net/code/narya/
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it
|
||||
// under the terms of the GNU Lesser General Public License as published
|
||||
// by the Free Software Foundation; either version 2.1 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package com.threerings.bureau.server;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
import com.threerings.presents.dobj.RootDObjectManager;
|
||||
import com.threerings.presents.server.PresentsSession;
|
||||
import com.threerings.presents.server.ShutdownManager;
|
||||
|
||||
import com.threerings.bureau.data.AgentObject;
|
||||
import com.threerings.bureau.data.BureauCredentials;
|
||||
|
||||
import static com.threerings.bureau.Log.log;
|
||||
|
||||
/**
|
||||
* Uses a TestServer to pound on the BureauRegistry. Sends random sequences of
|
||||
* startAgent and destroyAgent. Most aspects of the randomness are configurable using system
|
||||
* properties.
|
||||
* TODO: add more types of testing
|
||||
* TODO: allow a quitAfter configuration parameter to shut down automatically
|
||||
*/
|
||||
@Singleton
|
||||
public class RegistryTester
|
||||
{
|
||||
/**
|
||||
* Convenience function for getting an integral property. Also logs the value.
|
||||
*/
|
||||
public static int intProp (String name, int defaultVal)
|
||||
{
|
||||
String val = System.getProperty(name);
|
||||
if (val == null) {
|
||||
log.info("Property " + name + " is " + defaultVal);
|
||||
return defaultVal;
|
||||
}
|
||||
int ival = Integer.parseInt(val);
|
||||
log.info("Property " + name + " is " + ival);
|
||||
return ival;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new server and runs the registry tester on it.
|
||||
*/
|
||||
public static void main (String[] args)
|
||||
{
|
||||
Injector injector = Guice.createInjector(new TestServer.Module());
|
||||
TestServer server = injector.getInstance(TestServer.class);
|
||||
RegistryTester tester = injector.getInstance(RegistryTester.class);
|
||||
|
||||
try {
|
||||
server.init(injector);
|
||||
tester.start();
|
||||
server.run();
|
||||
|
||||
} catch (Exception e) {
|
||||
log.warning("Unable to initialize server.", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new registry tester.
|
||||
*/
|
||||
@Inject public RegistryTester (TestServer server, ShutdownManager shutmgr)
|
||||
{
|
||||
_server = server;
|
||||
|
||||
_maxAgents = intProp("maxAgents", 500);
|
||||
_numBureaus = intProp("numBureaus", 5);
|
||||
_maxOps = intProp("maxOps", 5);
|
||||
_killBureauChance = intProp("killBureauChance", 1);
|
||||
_createChance = intProp("createChance", 70);
|
||||
_minDelay = intProp("minDelay", 500);
|
||||
_maxDelay = intProp("maxDelay", 2000);
|
||||
_clientTarget = System.getProperty("clientTarget");
|
||||
if (_clientTarget == null) {
|
||||
_clientTarget = "bureau-runclient";
|
||||
}
|
||||
|
||||
// stop the tests when the server shuts down
|
||||
// TODO: this is not called on Ctrl-C, need a way to shut down gracefully
|
||||
shutmgr.registerShutdowner(new ShutdownManager.Shutdowner() {
|
||||
public void shutdown () {
|
||||
log.info("Shutting down tests");
|
||||
_stop = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts the test thread.
|
||||
*/
|
||||
public void start ()
|
||||
{
|
||||
_server.setClientTarget(_clientTarget);
|
||||
|
||||
Thread thread = new Thread("Registry test thread") {
|
||||
@Override
|
||||
public void run () {
|
||||
log.info(getName() + " started");
|
||||
runTestThread();
|
||||
log.info(getName() + " stopped");
|
||||
}
|
||||
};
|
||||
thread.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Stops the test thread.
|
||||
*/
|
||||
public void stop ()
|
||||
{
|
||||
_stop = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* The main loop for the tests.
|
||||
*/
|
||||
protected void runTestThread ()
|
||||
{
|
||||
// set up the rngs (2 are needed since one is called from the dobj thread)
|
||||
long seed = Long.parseLong(System.getProperty("seed", "0"));
|
||||
if (seed == 0) {
|
||||
seed = System.currentTimeMillis();
|
||||
}
|
||||
_rng1 = new Random(seed);
|
||||
_rng2 = new Random(seed);
|
||||
|
||||
log.info("Running tests, seed is " + seed);
|
||||
|
||||
// runnable that generates N requests to create or destroy agents
|
||||
Runnable doOp = new Runnable() {
|
||||
public void run () {
|
||||
int ops = 1 + _rng1.nextInt(_maxOps);
|
||||
log.info("Starting " + ops + " agent requests");
|
||||
for (int i = 0; i < ops; ++i) {
|
||||
randomlyDoOperation();
|
||||
}
|
||||
log.info("Finished " + ops + " agent requests");
|
||||
}
|
||||
};
|
||||
|
||||
// the main test loop
|
||||
while (!_stop) {
|
||||
try {
|
||||
// sleep for a bit
|
||||
int sleep = _maxDelay - _minDelay + 1;
|
||||
sleep = _minDelay + _rng2.nextInt(sleep);
|
||||
Thread.sleep(sleep);
|
||||
}
|
||||
catch (InterruptedException ie) {
|
||||
break;
|
||||
}
|
||||
|
||||
// create or destroy some agents
|
||||
_omgr.postRunnable(doOp);
|
||||
}
|
||||
|
||||
// clean up
|
||||
_omgr.postRunnable(new Runnable() {
|
||||
public void run () {
|
||||
for (AgentObject obj : _agents) {
|
||||
_bureauReg.destroyAgent(obj);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Chooses between killing a bureau connection or creating or destroying an agent.
|
||||
*/
|
||||
protected void randomlyDoOperation ()
|
||||
{
|
||||
if (_rng1.nextInt(100) < _killBureauChance) {
|
||||
log.info("Killing a bureau");
|
||||
PresentsSession bureau = getRandomBureau();
|
||||
if (bureau == null) {
|
||||
log.info("No bureaus to kill right now");
|
||||
return;
|
||||
}
|
||||
|
||||
String id = ((BureauCredentials)bureau.getCredentials()).clientId;
|
||||
log.info("Killing bureau " + id);
|
||||
bureau.endSession();
|
||||
|
||||
for (Iterator<AgentObject> i = _agents.iterator(); i.hasNext();) {
|
||||
AgentObject agent = i.next();
|
||||
if (agent.bureauId.equals(id)) {
|
||||
log.info("Removing agent " + agent.getOid());
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
randomlyCreateOrDestroyAgent();
|
||||
}
|
||||
}
|
||||
|
||||
protected PresentsSession getRandomBureau ()
|
||||
{
|
||||
boolean[] tried = new boolean[_numBureaus];
|
||||
for (int dead = 0; dead < _numBureaus;) {
|
||||
int index = _rng1.nextInt(_numBureaus);
|
||||
if (tried[index]) {
|
||||
continue;
|
||||
}
|
||||
String id = "test-" + (index + 1);
|
||||
PresentsSession client = _bureauReg.lookupClient(id);
|
||||
if (client == null) {
|
||||
++dead;
|
||||
} else {
|
||||
return client;
|
||||
}
|
||||
tried[index] = true;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does what the name says using the configuration values.
|
||||
*/
|
||||
protected void randomlyCreateOrDestroyAgent ()
|
||||
{
|
||||
int size = _agents.size();
|
||||
if (size >= _maxAgents ||
|
||||
(size != 0 && _rng1.nextInt(100) >= _createChance)) {
|
||||
AgentObject toRemove = _agents.remove(_rng1.nextInt(size));
|
||||
log.info("Destroying agent " + toRemove.getOid());
|
||||
_bureauReg.destroyAgent(toRemove);
|
||||
}
|
||||
else {
|
||||
AgentObject added = create(_rng1.nextInt(_numBureaus) + 1);
|
||||
_agents.add(added);
|
||||
log.info("Created agent " + added.getOid());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create and return a new agent for the given bureau.
|
||||
*/
|
||||
protected AgentObject create (int bureau)
|
||||
{
|
||||
AgentObject obj = new AgentObject();
|
||||
obj.bureauType = "test";
|
||||
obj.bureauId = "test-" + bureau;
|
||||
_bureauReg.startAgent(obj);
|
||||
return obj;
|
||||
}
|
||||
|
||||
@Inject protected RootDObjectManager _omgr;
|
||||
@Inject protected BureauRegistry _bureauReg;
|
||||
|
||||
protected TestServer _server;
|
||||
protected boolean _stop;
|
||||
protected Random _rng1;
|
||||
protected Random _rng2;
|
||||
protected List<AgentObject> _agents = Lists.newArrayList();
|
||||
|
||||
// maximum number of agents to keep around
|
||||
protected int _maxAgents;
|
||||
|
||||
// number of bureaus to select between
|
||||
protected int _numBureaus;
|
||||
|
||||
// number of operations to perform in one dobj queue task
|
||||
protected int _maxOps;
|
||||
|
||||
// chance of killing a buerau (if one exists)
|
||||
protected int _killBureauChance;
|
||||
|
||||
// chance of creating a new agent if limit has not been reached
|
||||
protected int _createChance;
|
||||
|
||||
// minimum delay between batches of requests
|
||||
protected int _minDelay;
|
||||
|
||||
// maximum delay between batches of requests
|
||||
protected int _maxDelay;
|
||||
|
||||
// ant target to use to kick off new bureaus
|
||||
protected String _clientTarget;
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
// Narya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2010 Three Rings Design, Inc., All Rights Reserved
|
||||
// http://www.threerings.net/code/narya/
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it
|
||||
// under the terms of the GNU Lesser General Public License as published
|
||||
// by the Free Software Foundation; either version 2.1 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package com.threerings.bureau.server;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Injector;
|
||||
import com.google.inject.Singleton;
|
||||
|
||||
import com.threerings.presents.server.PresentsServer;
|
||||
|
||||
import static com.threerings.bureau.Log.log;
|
||||
|
||||
/**
|
||||
* Extends a presents server to include a bureau registry.
|
||||
*/
|
||||
@Singleton
|
||||
public class TestServer extends PresentsServer
|
||||
{
|
||||
/**
|
||||
* Creates a new server and runs it.
|
||||
*/
|
||||
public static void main (String[] args)
|
||||
{
|
||||
Injector injector = Guice.createInjector(new Module());
|
||||
TestServer server = injector.getInstance(TestServer.class);
|
||||
try {
|
||||
server.init(injector);
|
||||
server.setClientTarget("bureau-runclient");
|
||||
server.run();
|
||||
|
||||
} catch (Exception e) {
|
||||
log.warning("Unable to initialize server.", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static BureauRegistry.CommandGenerator antCommandGenerator (final String target)
|
||||
{
|
||||
return new BureauRegistry.CommandGenerator() {
|
||||
public String[] createCommand (String bureauId, String token) {
|
||||
return new String[] {
|
||||
"ant",
|
||||
"-DserverName=localhost",
|
||||
"-DserverPort=47624",
|
||||
"-DbureauId=" + bureauId,
|
||||
"-Dtoken=" + token,
|
||||
target };
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public void setClientTarget (String target)
|
||||
{
|
||||
_bureauReg.setCommandGenerator("test", antCommandGenerator(target));
|
||||
}
|
||||
|
||||
@Inject protected BureauRegistry _bureauReg;
|
||||
}
|
||||
@@ -1,110 +0,0 @@
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
// Narya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2010 Three Rings Design, Inc., All Rights Reserved
|
||||
// http://www.threerings.net/code/narya/
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it
|
||||
// under the terms of the GNU Lesser General Public License as published
|
||||
// by the Free Software Foundation; either version 2.1 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package com.threerings.crowd.client;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
|
||||
import com.samskivert.swing.util.SwingUtil;
|
||||
|
||||
import com.threerings.util.Name;
|
||||
|
||||
import com.threerings.presents.client.Client;
|
||||
import com.threerings.presents.net.UsernamePasswordCreds;
|
||||
|
||||
import static com.threerings.crowd.Log.log;
|
||||
|
||||
/**
|
||||
* The main point of entry for the Jabber client application. It creates
|
||||
* and initializes the myriad components of the client and sets all the
|
||||
* proper wheels in motion.
|
||||
*/
|
||||
public class JabberApp
|
||||
{
|
||||
public void init ()
|
||||
throws IOException
|
||||
{
|
||||
// create a frame
|
||||
_frame = new JFrame("Jabber Client");
|
||||
|
||||
// initialize our client instance
|
||||
_client = new JabberClient();
|
||||
_client.init(_frame);
|
||||
}
|
||||
|
||||
public void run (
|
||||
String server, String username, String password, int roomId)
|
||||
{
|
||||
// position everything and show the frame
|
||||
_frame.setSize(800, 600);
|
||||
SwingUtil.centerWindow(_frame);
|
||||
_frame.setVisible(true);
|
||||
|
||||
_client.setRoom(roomId);
|
||||
Client client = _client.getContext().getClient();
|
||||
|
||||
// pass them on to the client
|
||||
log.info("Using [server=" + server + "].");
|
||||
client.setServer(server, Client.DEFAULT_SERVER_PORTS);
|
||||
|
||||
// configure the client with some credentials and logon
|
||||
if (username != null && password != null) {
|
||||
// create and set our credentials
|
||||
client.setCredentials(
|
||||
new UsernamePasswordCreds(new Name(username), password));
|
||||
client.logon();
|
||||
}
|
||||
}
|
||||
|
||||
public static void main (String[] args)
|
||||
{
|
||||
String server = "localhost";
|
||||
if (args.length > 0) {
|
||||
server = args[0];
|
||||
}
|
||||
String username = (args.length > 1) ? args[1] : null;
|
||||
String password = (args.length > 2) ? args[2] : null;
|
||||
int roomId = 2;
|
||||
if (args.length > 4) {
|
||||
try {
|
||||
roomId = Integer.parseInt(args[4]);
|
||||
} catch (NumberFormatException e) {
|
||||
// so what?
|
||||
}
|
||||
}
|
||||
|
||||
JabberApp app = new JabberApp();
|
||||
try {
|
||||
// initialize the app
|
||||
app.init();
|
||||
} catch (IOException ioe) {
|
||||
log.warning("Error initializing application.", ioe);
|
||||
}
|
||||
|
||||
// and run it
|
||||
app.run(server, username, password, roomId);
|
||||
}
|
||||
|
||||
protected JabberClient _client;
|
||||
protected JFrame _frame;
|
||||
}
|
||||
@@ -1,246 +0,0 @@
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
// Narya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2010 Three Rings Design, Inc., All Rights Reserved
|
||||
// http://www.threerings.net/code/narya/
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it
|
||||
// under the terms of the GNU Lesser General Public License as published
|
||||
// by the Free Software Foundation; either version 2.1 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package com.threerings.crowd.client;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import com.samskivert.util.Config;
|
||||
import com.samskivert.util.RunQueue;
|
||||
|
||||
import com.threerings.util.MessageManager;
|
||||
|
||||
import com.threerings.presents.client.Client;
|
||||
import com.threerings.presents.client.SessionObserver;
|
||||
import com.threerings.presents.dobj.DObjectManager;
|
||||
|
||||
import com.threerings.crowd.chat.client.ChatDirector;
|
||||
import com.threerings.crowd.util.CrowdContext;
|
||||
|
||||
/**
|
||||
* The Jabber client takes care of instantiating all of the proper
|
||||
* managers and loading up all of the necessary configuration and getting
|
||||
* the client bootstrapped. It can be extended by games that require an
|
||||
* extended context implementation.
|
||||
*/
|
||||
public class JabberClient
|
||||
implements SessionObserver
|
||||
{
|
||||
/**
|
||||
* Initializes a new client and provides it with a frame in which to
|
||||
* display everything.
|
||||
*/
|
||||
public void init (JFrame frame)
|
||||
throws IOException
|
||||
{
|
||||
// create our context
|
||||
_ctx = createContextImpl();
|
||||
|
||||
// create the directors/managers/etc. provided by the context
|
||||
createContextServices();
|
||||
|
||||
// for test purposes, hardcode the server info
|
||||
_client.setServer("localhost", Client.DEFAULT_SERVER_PORTS);
|
||||
_client.addClientObserver(this);
|
||||
|
||||
// keep this for later
|
||||
_frame = frame;
|
||||
|
||||
// log off when they close the window
|
||||
_frame.addWindowListener(new WindowAdapter() {
|
||||
@Override public void windowClosing (WindowEvent evt) {
|
||||
// if we're logged on, log off
|
||||
if (_client.isLoggedOn()) {
|
||||
_client.logoff(true);
|
||||
} else {
|
||||
// otherwise get the heck out
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the roomId to which we will connect upon logon.
|
||||
*/
|
||||
public void setRoom (int roomId)
|
||||
{
|
||||
_roomId = roomId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a reference to the context in effect for this client. This
|
||||
* reference is valid for the lifetime of the application.
|
||||
*/
|
||||
public CrowdContext getContext ()
|
||||
{
|
||||
return _ctx;
|
||||
}
|
||||
|
||||
// documentation inherited from interface SessionObserver
|
||||
public void clientWillLogon (Client client)
|
||||
{
|
||||
}
|
||||
|
||||
// documentation inherited from interface SessionObserver
|
||||
public void clientDidLogon (Client client)
|
||||
{
|
||||
// enter the one and only chat room; giant hack warning: we know
|
||||
// that the place we're headed to is ID 2 because there's only one
|
||||
// place on the whole server; a normal client would either issue
|
||||
// an invocation service request at this point or look at
|
||||
// something in the BootstrapData to figure out what to do
|
||||
_ctx.getLocationDirector().moveTo(_roomId);
|
||||
}
|
||||
|
||||
// documentation inherited from interface SessionObserver
|
||||
public void clientObjectDidChange (Client client)
|
||||
{
|
||||
// nada
|
||||
}
|
||||
|
||||
// documentation inherited from interface SessionObserver
|
||||
public void clientDidLogoff (Client client)
|
||||
{
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the {@link CrowdContext} implementation that will be
|
||||
* passed around to all of the client code. Derived classes may wish
|
||||
* to override this and create some extended context implementation.
|
||||
*/
|
||||
protected CrowdContext createContextImpl ()
|
||||
{
|
||||
return new JabberContextImpl();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates and initializes the various services that are provided by
|
||||
* the context. Derived classes that provide an extended context
|
||||
* should override this method and create their own extended
|
||||
* services. They should be sure to call
|
||||
* <code>super.createContextServices</code>.
|
||||
*/
|
||||
protected void createContextServices ()
|
||||
throws IOException
|
||||
{
|
||||
// create the handles on our various services
|
||||
_client = new Client(null, RunQueue.AWT);
|
||||
|
||||
// create our managers and directors
|
||||
_locdir = new LocationDirector(_ctx);
|
||||
_occdir = new OccupantDirector(_ctx);
|
||||
_msgmgr = new MessageManager(MESSAGE_MANAGER_PREFIX);
|
||||
_chatdir = new ChatDirector(_ctx, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* The context implementation. This provides access to all of the
|
||||
* objects and services that are needed by the operating client.
|
||||
*/
|
||||
protected class JabberContextImpl implements CrowdContext
|
||||
{
|
||||
/**
|
||||
* Apparently the default constructor has default access, rather
|
||||
* than protected access, even though this class is declared to be
|
||||
* protected. Why, I don't know, but we need to be able to extend
|
||||
* this class elsewhere, so we need this.
|
||||
*/
|
||||
protected JabberContextImpl ()
|
||||
{
|
||||
}
|
||||
|
||||
public Client getClient ()
|
||||
{
|
||||
return _client;
|
||||
}
|
||||
|
||||
public DObjectManager getDObjectManager ()
|
||||
{
|
||||
return _client.getDObjectManager();
|
||||
}
|
||||
|
||||
public Config getConfig ()
|
||||
{
|
||||
return _config;
|
||||
}
|
||||
|
||||
public LocationDirector getLocationDirector ()
|
||||
{
|
||||
return _locdir;
|
||||
}
|
||||
|
||||
public OccupantDirector getOccupantDirector ()
|
||||
{
|
||||
return _occdir;
|
||||
}
|
||||
|
||||
public ChatDirector getChatDirector ()
|
||||
{
|
||||
return _chatdir;
|
||||
}
|
||||
|
||||
public MessageManager getMessageManager ()
|
||||
{
|
||||
return _msgmgr;
|
||||
}
|
||||
|
||||
public void setPlaceView (PlaceView view)
|
||||
{
|
||||
JPanel panel = (JPanel)view;
|
||||
// remove the old panel
|
||||
_frame.getContentPane().removeAll();
|
||||
// add the new one
|
||||
_frame.getContentPane().add(panel, BorderLayout.CENTER);
|
||||
// swing doesn't properly repaint after adding/removing children
|
||||
panel.revalidate();
|
||||
_frame.repaint();
|
||||
}
|
||||
|
||||
public void clearPlaceView (PlaceView view)
|
||||
{
|
||||
// we'll just let the next place view replace our old one
|
||||
}
|
||||
}
|
||||
|
||||
protected CrowdContext _ctx;
|
||||
protected JFrame _frame;
|
||||
protected Config _config = new Config("jabber");
|
||||
|
||||
protected Client _client;
|
||||
protected LocationDirector _locdir;
|
||||
protected OccupantDirector _occdir;
|
||||
protected ChatDirector _chatdir;
|
||||
protected MessageManager _msgmgr;
|
||||
protected int _roomId;
|
||||
|
||||
/** The prefix prepended to localization bundle names before looking
|
||||
* them up in the classpath. */
|
||||
protected static final String MESSAGE_MANAGER_PREFIX = "rsrc.i18n";
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
//
|
||||
// $Id$
|
||||
|
||||
package com.threerings.crowd.client;
|
||||
|
||||
import com.threerings.crowd.util.CrowdContext;
|
||||
|
||||
/**
|
||||
* Handles the basic bits for our simple chat room.
|
||||
*/
|
||||
public class JabberController extends PlaceController
|
||||
{
|
||||
@Override
|
||||
protected PlaceView createPlaceView (CrowdContext ctx)
|
||||
{
|
||||
return new JabberPanel(ctx);
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
//
|
||||
// $Id$
|
||||
|
||||
package com.threerings.crowd.client;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
|
||||
import javax.swing.JPanel;
|
||||
|
||||
import com.threerings.crowd.data.PlaceObject;
|
||||
import com.threerings.crowd.util.CrowdContext;
|
||||
|
||||
// import com.threerings.micasa.client.ChatPanel;
|
||||
// import com.threerings.micasa.client.OccupantList;
|
||||
|
||||
/**
|
||||
* Displays a simple chat view.
|
||||
*/
|
||||
public class JabberPanel extends JPanel
|
||||
implements PlaceView
|
||||
{
|
||||
public JabberPanel (CrowdContext ctx)
|
||||
{
|
||||
_ctx = ctx;
|
||||
setLayout(new BorderLayout());
|
||||
// add(new ChatPanel(ctx), BorderLayout.CENTER);
|
||||
// add(new OccupantList(ctx), BorderLayout.EAST);
|
||||
}
|
||||
|
||||
// documentation inherited from interface PlaceView
|
||||
public void willEnterPlace (PlaceObject plobj)
|
||||
{
|
||||
}
|
||||
|
||||
// documentation inherited from interface PlaceView
|
||||
public void didLeavePlace (PlaceObject plobj)
|
||||
{
|
||||
}
|
||||
|
||||
protected CrowdContext _ctx;
|
||||
}
|
||||
@@ -1,186 +0,0 @@
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
// Narya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2010 Three Rings Design, Inc., All Rights Reserved
|
||||
// http://www.threerings.net/code/narya/
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it
|
||||
// under the terms of the GNU Lesser General Public License as published
|
||||
// by the Free Software Foundation; either version 2.1 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package com.threerings.crowd.client;
|
||||
|
||||
import com.samskivert.util.BasicRunQueue;
|
||||
import com.samskivert.util.Config;
|
||||
|
||||
import com.threerings.util.MessageManager;
|
||||
import com.threerings.util.Name;
|
||||
|
||||
import com.threerings.presents.client.Client;
|
||||
import com.threerings.presents.client.ClientObserver;
|
||||
import com.threerings.presents.dobj.DObjectManager;
|
||||
import com.threerings.presents.net.UsernamePasswordCreds;
|
||||
|
||||
import com.threerings.crowd.chat.client.ChatDirector;
|
||||
import com.threerings.crowd.util.CrowdContext;
|
||||
|
||||
import static com.threerings.crowd.Log.log;
|
||||
|
||||
public class TestClient
|
||||
implements ClientObserver
|
||||
{
|
||||
public TestClient (String username)
|
||||
{
|
||||
// create our context
|
||||
_ctx = createContext();
|
||||
|
||||
// create the handles on our various services
|
||||
_client = new Client(new UsernamePasswordCreds(new Name(username), "test"), _rqueue);
|
||||
_locdir = new LocationDirector(_ctx);
|
||||
_occdir = new OccupantDirector(_ctx);
|
||||
_msgmgr = new MessageManager("rsrc");
|
||||
_chatdir = new ChatDirector(_ctx, "global");
|
||||
|
||||
// we want to know about logon/logoff
|
||||
_client.addClientObserver(this);
|
||||
|
||||
// for test purposes, hardcode the server info
|
||||
_client.setServer("localhost", Client.DEFAULT_SERVER_PORTS);
|
||||
}
|
||||
|
||||
public void run ()
|
||||
{
|
||||
// log on
|
||||
_client.logon();
|
||||
|
||||
// loop over our queue, running the runnables
|
||||
_rqueue.run();
|
||||
}
|
||||
|
||||
public void clientWillLogon (Client client)
|
||||
{
|
||||
}
|
||||
|
||||
public void clientDidLogon (Client client)
|
||||
{
|
||||
log.info("Client did logon [client=" + client + "].");
|
||||
|
||||
// request to move to a place
|
||||
_ctx.getLocationDirector().moveTo(15);
|
||||
}
|
||||
|
||||
public void clientObjectDidChange (Client client)
|
||||
{
|
||||
log.info("Client object did change [client=" + client + "].");
|
||||
}
|
||||
|
||||
public void clientFailedToLogon (Client client, Exception cause)
|
||||
{
|
||||
log.info("Client failed to logon [client=" + client +
|
||||
", cause=" + cause + "].");
|
||||
}
|
||||
|
||||
public void clientConnectionFailed (Client client, Exception cause)
|
||||
{
|
||||
log.info("Client connection failed [client=" + client +
|
||||
", cause=" + cause + "].");
|
||||
}
|
||||
|
||||
public boolean clientWillLogoff (Client client)
|
||||
{
|
||||
log.info("Client will logoff [client=" + client + "].");
|
||||
return true;
|
||||
}
|
||||
|
||||
public void clientDidLogoff (Client client)
|
||||
{
|
||||
log.info("Client did logoff [client=" + client + "].");
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
public void clientDidClear (Client client)
|
||||
{
|
||||
}
|
||||
|
||||
protected CrowdContext createContext ()
|
||||
{
|
||||
return new CrowdContextImpl();
|
||||
}
|
||||
|
||||
public static void main (String[] args)
|
||||
{
|
||||
// create our test client
|
||||
TestClient tclient = new TestClient("test");
|
||||
// start it running
|
||||
tclient.run();
|
||||
}
|
||||
|
||||
protected class CrowdContextImpl implements CrowdContext
|
||||
{
|
||||
public Config getConfig ()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public Client getClient ()
|
||||
{
|
||||
return _client;
|
||||
}
|
||||
|
||||
public DObjectManager getDObjectManager ()
|
||||
{
|
||||
return _client.getDObjectManager();
|
||||
}
|
||||
|
||||
public LocationDirector getLocationDirector ()
|
||||
{
|
||||
return _locdir;
|
||||
}
|
||||
|
||||
public OccupantDirector getOccupantDirector ()
|
||||
{
|
||||
return _occdir;
|
||||
}
|
||||
|
||||
public ChatDirector getChatDirector ()
|
||||
{
|
||||
return _chatdir;
|
||||
}
|
||||
|
||||
public MessageManager getMessageManager ()
|
||||
{
|
||||
return _msgmgr;
|
||||
}
|
||||
|
||||
public void setPlaceView (PlaceView view)
|
||||
{
|
||||
// nothing to do because we don't create views
|
||||
}
|
||||
|
||||
public void clearPlaceView (PlaceView view)
|
||||
{
|
||||
// nothing to do because we don't create views
|
||||
}
|
||||
}
|
||||
|
||||
protected Client _client;
|
||||
protected CrowdContext _ctx;
|
||||
|
||||
protected LocationDirector _locdir;
|
||||
protected OccupantDirector _occdir;
|
||||
protected MessageManager _msgmgr;
|
||||
protected ChatDirector _chatdir;
|
||||
|
||||
protected BasicRunQueue _rqueue = new BasicRunQueue();
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
//
|
||||
// $Id$
|
||||
|
||||
package com.threerings.crowd.data;
|
||||
|
||||
import com.threerings.crowd.client.JabberController;
|
||||
import com.threerings.crowd.client.PlaceController;
|
||||
|
||||
/**
|
||||
* Defines the necessary bits for our chat room.
|
||||
*/
|
||||
public class JabberConfig extends PlaceConfig
|
||||
{
|
||||
// documentation inherited
|
||||
@Override
|
||||
public PlaceController createController ()
|
||||
{
|
||||
return new JabberController();
|
||||
}
|
||||
|
||||
// documentation inherited
|
||||
@Override
|
||||
public String getManagerClassName ()
|
||||
{
|
||||
// nothing special needed on the server side
|
||||
return "com.threerings.crowd.server.PlaceManager";
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
//
|
||||
// $Id$
|
||||
|
||||
package com.threerings.crowd.server;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
import com.threerings.crowd.data.JabberConfig;
|
||||
|
||||
import static com.threerings.crowd.Log.log;
|
||||
|
||||
/**
|
||||
* A basic server that creates a single room and sticks everyone in it where they can chat with one
|
||||
* another.
|
||||
*/
|
||||
public class JabberServer extends CrowdServer
|
||||
{
|
||||
public static void main (String[] args)
|
||||
{
|
||||
Injector injector = Guice.createInjector(new Module());
|
||||
JabberServer server = injector.getInstance(JabberServer.class);
|
||||
|
||||
try {
|
||||
server.init(injector);
|
||||
server.run();
|
||||
} catch (Exception e) {
|
||||
log.warning("Unable to initialize server.", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override // from CrowdServer
|
||||
public void init (Injector injector)
|
||||
throws Exception
|
||||
{
|
||||
super.init(injector);
|
||||
|
||||
// create a single location
|
||||
_pmgr = _plreg.createPlace(new JabberConfig());
|
||||
}
|
||||
|
||||
protected PlaceManager _pmgr;
|
||||
}
|
||||
@@ -1,91 +0,0 @@
|
||||
package com.threerings.io;
|
||||
|
||||
//
|
||||
//$Id$
|
||||
//
|
||||
//Narya library - tools for developing networked games
|
||||
//Copyright (C) 2002-2010 Three Rings Design, Inc., All Rights Reserved
|
||||
//http://www.threerings.net/code/narya/
|
||||
//
|
||||
//This library is free software; you can redistribute it and/or modify it
|
||||
//under the terms of the GNU Lesser General Public License as published
|
||||
//by the Free Software Foundation; either version 2.1 of the License, or
|
||||
//(at your option) any later version.
|
||||
//
|
||||
//This library is distributed in the hope that it will be useful,
|
||||
//but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
//Lesser General Public License for more details.
|
||||
//
|
||||
//You should have received a copy of the GNU Lesser General Public
|
||||
//License along with this library; if not, write to the Free Software
|
||||
//Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.samskivert.util.Mapping;
|
||||
|
||||
public class ASStreamableSubset extends SimpleStreamableObject
|
||||
{
|
||||
public boolean bool1 = true;
|
||||
public short short2 = 2;
|
||||
public int int3 = 3;
|
||||
public long long4 = 4;
|
||||
public float float5 = 5;
|
||||
public double double6 = 6;
|
||||
public char char7 = (char)7;
|
||||
public byte byte8 = 8;
|
||||
|
||||
public String string1 = "one";
|
||||
public String nullString1;
|
||||
|
||||
public boolean[] bools = new boolean[] { true, false, true };
|
||||
public byte[] bytes = new byte[] { 1, 2, 3 };
|
||||
public int[] ints = new int[] { 1, 2, 3 };
|
||||
|
||||
public boolean[] nullBools;
|
||||
public byte[] nullBytes;
|
||||
public int[] nullInts;
|
||||
|
||||
public List<String> strings = Lists.newArrayList("one", "two", "three");
|
||||
public List<String> nullStrings;
|
||||
|
||||
public Map<String, String> stringMap = Mapping.of("one", "1", "two", "2", "three", "3");
|
||||
public Map<String, Integer> stringIntMap = Mapping.of("one", 1, "two", 2, "three", 3);
|
||||
public Map<String, String> nullStringMap;
|
||||
|
||||
@Override
|
||||
public boolean equals (Object other)
|
||||
{
|
||||
if (!(other instanceof ASStreamableSubset)) {
|
||||
return false;
|
||||
}
|
||||
ASStreamableSubset ow = (ASStreamableSubset)other;
|
||||
return bool1 == ow.bool1 && byte8 == ow.byte8 && char7 == ow.char7 && short2 == ow.short2
|
||||
&& int3 == ow.int3 && long4 == ow.long4
|
||||
&& float5 == ow.float5
|
||||
&& double6 == ow.double6
|
||||
&&
|
||||
|
||||
Objects.equal(string1, ow.string1)
|
||||
&& Objects.equal(nullString1, ow.nullString1)
|
||||
&&
|
||||
|
||||
Arrays.equals(bools, ow.bools) && Arrays.equals(bytes, ow.bytes)
|
||||
&& Arrays.equals(ints, ow.ints) &&
|
||||
|
||||
Arrays.equals(nullBools, ow.nullBools) && Arrays.equals(nullBytes, ow.nullBytes)
|
||||
&& Arrays.equals(nullInts, ow.nullInts)
|
||||
&&
|
||||
|
||||
Objects.equal(strings, ow.strings) && Objects.equal(nullStrings, ow.nullStrings)
|
||||
&&
|
||||
|
||||
Objects.equal(stringMap, ow.stringMap) && Objects.equal(stringIntMap, ow.stringIntMap)
|
||||
&& Objects.equal(nullStringMap, ow.nullStringMap);
|
||||
}
|
||||
}
|
||||
@@ -1,131 +0,0 @@
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
// Narya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2010 Three Rings Design, Inc., All Rights Reserved
|
||||
// http://www.threerings.net/code/narya/
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it
|
||||
// under the terms of the GNU Lesser General Public License as published
|
||||
// by the Free Software Foundation; either version 2.1 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package com.threerings.io;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import java.nio.channels.Pipe;
|
||||
import java.nio.channels.ReadableByteChannel;
|
||||
import java.nio.channels.WritableByteChannel;
|
||||
import java.nio.channels.spi.SelectorProvider;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class FrameTest extends TestCase
|
||||
{
|
||||
public FrameTest ()
|
||||
{
|
||||
super(FrameTest.class.getName());
|
||||
}
|
||||
|
||||
public void writeFrames (WritableByteChannel out)
|
||||
throws IOException
|
||||
{
|
||||
FramingOutputStream fout = new FramingOutputStream();
|
||||
DataOutputStream dout = new DataOutputStream(fout);
|
||||
|
||||
// create a few frames and write them to the output stream
|
||||
dout.writeUTF(STRING1);
|
||||
dout.writeUTF(STRING2);
|
||||
dout.writeUTF(STRING3);
|
||||
out.write(fout.frameAndReturnBuffer());
|
||||
fout.resetFrame();
|
||||
|
||||
dout.writeUTF(STRING4);
|
||||
dout.writeUTF(STRING5);
|
||||
dout.writeUTF(STRING6);
|
||||
out.write(fout.frameAndReturnBuffer());
|
||||
fout.resetFrame();
|
||||
|
||||
dout.writeUTF(STRING7);
|
||||
out.write(fout.frameAndReturnBuffer());
|
||||
fout.resetFrame();
|
||||
}
|
||||
|
||||
public void readFrames (ReadableByteChannel in)
|
||||
throws IOException
|
||||
{
|
||||
FramedInputStream fin = new FramedInputStream();
|
||||
DataInputStream din = new DataInputStream(fin);
|
||||
|
||||
// read the first frame
|
||||
fin.readFrame(in);
|
||||
assertTrue("string1", STRING1.equals(din.readUTF()));
|
||||
assertTrue("string2", STRING2.equals(din.readUTF()));
|
||||
assertTrue("string3", STRING3.equals(din.readUTF()));
|
||||
assertTrue("hit eof", fin.read() == -1);
|
||||
|
||||
// read the second frame
|
||||
fin.readFrame(in);
|
||||
assertTrue("string4", STRING4.equals(din.readUTF()));
|
||||
assertTrue("string5", STRING5.equals(din.readUTF()));
|
||||
assertTrue("string6", STRING6.equals(din.readUTF()));
|
||||
assertTrue("hit eof", fin.read() == -1);
|
||||
|
||||
// read the third frame
|
||||
fin.readFrame(in);
|
||||
assertTrue("string7", STRING7.equals(din.readUTF()));
|
||||
assertTrue("hit eof", fin.read() == -1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runTest ()
|
||||
{
|
||||
try {
|
||||
Pipe pipe = SelectorProvider.provider().openPipe();
|
||||
writeFrames(pipe.sink());
|
||||
readFrames(pipe.source());
|
||||
|
||||
} catch (IOException ioe) {
|
||||
ioe.printStackTrace(System.err);
|
||||
}
|
||||
}
|
||||
|
||||
public static Test suite ()
|
||||
{
|
||||
return new FrameTest();
|
||||
}
|
||||
|
||||
public static void main (String[] args)
|
||||
{
|
||||
FrameTest test = new FrameTest();
|
||||
test.runTest();
|
||||
}
|
||||
|
||||
protected static final String STRING1 = "This is a test.";
|
||||
protected static final String STRING2 = "This is only a test.";
|
||||
protected static final String STRING3 =
|
||||
"If this were not a test, there would be meaningful data in " +
|
||||
"this frame and someone would probably be enjoying themselves.";
|
||||
|
||||
protected static final String STRING4 =
|
||||
"Now is the time for all good men to come to the aid of " +
|
||||
"their country.";
|
||||
protected static final String STRING5 = "Every good boy deserves fudge.";
|
||||
protected static final String STRING6 =
|
||||
"The quick brown fox jumped over the lazy dog.";
|
||||
|
||||
protected static final String STRING7 = "Third time is the charm.";
|
||||
}
|
||||
@@ -1,431 +0,0 @@
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
// Narya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2010 Three Rings Design, Inc., All Rights Reserved
|
||||
// http://www.threerings.net/code/narya/
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it
|
||||
// under the terms of the GNU Lesser General Public License as published
|
||||
// by the Free Software Foundation; either version 2.1 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package com.threerings.io;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import com.samskivert.util.StringUtil;
|
||||
import com.samskivert.util.Tuple;
|
||||
|
||||
import com.threerings.io.Intern;
|
||||
import com.threerings.util.StreamableTuple;
|
||||
|
||||
/**
|
||||
* Tests the {@link Streamable} class.
|
||||
*/
|
||||
public class StreamableTest
|
||||
{
|
||||
public static class Widget extends SimpleStreamableObject
|
||||
implements Cloneable
|
||||
{
|
||||
public boolean bool1 = true;
|
||||
public byte byte1 = Byte.MAX_VALUE;
|
||||
public char char1 = 'a';
|
||||
public short short1 = Short.MAX_VALUE;
|
||||
public int int1 = Integer.MAX_VALUE;
|
||||
public long long1 = Long.MAX_VALUE;
|
||||
public float float1 = Float.MAX_VALUE;
|
||||
public double double1 = Double.MAX_VALUE;
|
||||
|
||||
public Boolean boxedBool = true;
|
||||
public Byte boxedByte = Byte.MAX_VALUE;
|
||||
public Character boxedChar = 'a';
|
||||
public Short boxedShort = Short.MAX_VALUE;
|
||||
public Integer boxedInt = Integer.MAX_VALUE;
|
||||
public Long boxedLong = Long.MAX_VALUE;
|
||||
public Float boxedFloat = Float.MAX_VALUE;
|
||||
public Double boxedDouble = Double.MAX_VALUE;
|
||||
|
||||
public Boolean nullBoxedBool;
|
||||
public Byte nullBoxedByte;
|
||||
public Character nullBoxedChar;
|
||||
public Short nullBoxedShort;
|
||||
public Integer nullBoxedInt;
|
||||
public Long nullBoxedLong;
|
||||
public Float nullBoxedFloat;
|
||||
public Double nullBoxedDouble;
|
||||
|
||||
public String string1 = "one";
|
||||
public String nullString1;
|
||||
|
||||
@Intern public String internedString1 = "monkey butter";
|
||||
@Intern public String nullInternedString1;
|
||||
|
||||
public Date date1 = new Date(42L);
|
||||
// public Date nullDate1; // null Date is apparently not supported, interesting!
|
||||
|
||||
// note: must be a Streamable class
|
||||
public Class<?> class1 = Widget.class;
|
||||
public Class<?> nullClass1;
|
||||
|
||||
public boolean[] bools = new boolean[] { true, false, true };
|
||||
public byte[] bytes = new byte[] { Byte.MAX_VALUE, 2, 3 };
|
||||
public short[] shorts = new short[] { Short.MAX_VALUE, 2, 3 };
|
||||
public char[] chars = new char[] { 'a', 'b', 'c' };
|
||||
public int[] ints = new int[] { Integer.MAX_VALUE, 2, 3 };
|
||||
public long[] longs = new long[] { Long.MAX_VALUE, 2, 3 };
|
||||
public float[] floats = new float[] { Float.MAX_VALUE, 2, 3 };
|
||||
public double[] doubles = new double[] { Double.MAX_VALUE, 2, 3 };
|
||||
|
||||
public boolean[] nullBools;
|
||||
public byte[] nullBytes;
|
||||
public short[] nullShorts;
|
||||
public char[] nullChars;
|
||||
public int[] nullInts;
|
||||
public long[] nullLongs;
|
||||
public float[] nullFloats;
|
||||
public double[] nullDoubles;
|
||||
|
||||
public Wocket wocket1 = new Wocket();
|
||||
public Wocket[] wockets = new Wocket[] { new Wocket(), new Wocket() };
|
||||
public Wicket[] wickets = new Wicket[] { new Wicket(), new Wicket(), new Wicket() };
|
||||
|
||||
public Wocket nullWocket1;
|
||||
public Wocket[] nullWockets;
|
||||
public Wicket[] nullWickets;
|
||||
|
||||
// it's legal for an Object field to contain a Streamable reference
|
||||
public Object object1 = new Wocket();
|
||||
public Object nullObject1 = new Wocket();
|
||||
|
||||
// it's legal for an Object[] field to contain an array of Streamable references; NOTE:
|
||||
// this will come back as "new Object[] { new Wocket(), new Wocket() }", so it's not kosher
|
||||
// to rely on the type of your array being preserved, only the type of its contents
|
||||
public Object[] objects = new Wocket[] { new Wocket(), new Wocket() };
|
||||
public Object[] nullObjects;
|
||||
|
||||
public List<Integer> list = Lists.newArrayList(1, 2, 3);
|
||||
public List<Integer> nullList = null;
|
||||
public ArrayList<Integer> arrayList = Lists.newArrayList(3, 2, 1);
|
||||
public ArrayList<Integer> nullArrayList = null;
|
||||
|
||||
public Collection<Integer> collection = Arrays.asList(4, 5, 6);
|
||||
public Collection<Integer> nullCollection = null;
|
||||
|
||||
public Set<Integer> set = Sets.newHashSet(6, 7, 8);
|
||||
public Set<Integer> nullSet = null;
|
||||
public HashSet<Integer> hashSet = Sets.newHashSet(7, 8, 9);
|
||||
public HashSet<Integer> nullHashSet = null;
|
||||
|
||||
public Map<Integer, String> map = ImmutableMap.of(1, "one", 2, "two", 3, "three");
|
||||
public Map<Integer, String> nullMap = null;
|
||||
public HashMap<String, Integer> hashMap = Maps.newHashMap(
|
||||
ImmutableMap.of("one", 1, "two", 2, "three", 3));
|
||||
public HashMap<String, Integer> nullHashMap = null;
|
||||
|
||||
@Override
|
||||
public boolean equals (Object other) {
|
||||
if (!(other instanceof Widget)) {
|
||||
return false;
|
||||
}
|
||||
Widget ow = (Widget)other;
|
||||
return bool1 == ow.bool1 &&
|
||||
byte1 == ow.byte1 &&
|
||||
char1 == ow.char1 &&
|
||||
short1 == ow.short1 &&
|
||||
int1 == ow.int1 &&
|
||||
long1 == ow.long1 &&
|
||||
float1 == ow.float1 &&
|
||||
double1 == ow.double1 &&
|
||||
|
||||
Objects.equal(boxedBool, ow.boxedBool) &&
|
||||
Objects.equal(boxedByte, ow.boxedByte) &&
|
||||
Objects.equal(boxedShort, ow.boxedShort) &&
|
||||
Objects.equal(boxedChar, ow.boxedChar) &&
|
||||
Objects.equal(boxedInt, ow.boxedInt) &&
|
||||
Objects.equal(boxedLong, ow.boxedLong) &&
|
||||
Objects.equal(boxedFloat, ow.boxedFloat) &&
|
||||
Objects.equal(boxedDouble, ow.boxedDouble) &&
|
||||
|
||||
Objects.equal(nullBoxedBool, ow.nullBoxedBool) &&
|
||||
Objects.equal(nullBoxedByte, ow.nullBoxedByte) &&
|
||||
Objects.equal(nullBoxedShort, ow.nullBoxedShort) &&
|
||||
Objects.equal(nullBoxedChar, ow.nullBoxedChar) &&
|
||||
Objects.equal(nullBoxedInt, ow.nullBoxedInt) &&
|
||||
Objects.equal(nullBoxedLong, ow.nullBoxedLong) &&
|
||||
Objects.equal(nullBoxedFloat, ow.nullBoxedFloat) &&
|
||||
Objects.equal(nullBoxedDouble, ow.nullBoxedDouble) &&
|
||||
|
||||
Objects.equal(string1, ow.string1) &&
|
||||
Objects.equal(nullString1, ow.nullString1) &&
|
||||
|
||||
internedString1 == ow.internedString1 &&
|
||||
nullInternedString1 == ow.nullInternedString1 &&
|
||||
|
||||
Objects.equal(date1, ow.date1) &&
|
||||
// Objects.equal(nullDate1, ow.nullDate1) &&
|
||||
|
||||
class1 == ow.class1 &&
|
||||
nullClass1 == ow.nullClass1 &&
|
||||
|
||||
Arrays.equals(bools, ow.bools) &&
|
||||
Arrays.equals(bytes, ow.bytes) &&
|
||||
Arrays.equals(shorts, ow.shorts) &&
|
||||
Arrays.equals(chars, ow.chars) &&
|
||||
Arrays.equals(ints, ow.ints) &&
|
||||
Arrays.equals(longs, ow.longs) &&
|
||||
Arrays.equals(floats, ow.floats) &&
|
||||
Arrays.equals(doubles, ow.doubles) &&
|
||||
|
||||
Arrays.equals(nullBools, ow.nullBools) &&
|
||||
Arrays.equals(nullBytes, ow.nullBytes) &&
|
||||
Arrays.equals(nullShorts, ow.nullShorts) &&
|
||||
Arrays.equals(nullChars, ow.nullChars) &&
|
||||
Arrays.equals(nullInts, ow.nullInts) &&
|
||||
Arrays.equals(nullLongs, ow.nullLongs) &&
|
||||
Arrays.equals(nullFloats, ow.nullFloats) &&
|
||||
Arrays.equals(nullDoubles, ow.nullDoubles) &&
|
||||
|
||||
Objects.equal(wocket1, ow.wocket1) &&
|
||||
Arrays.equals(wockets, ow.wockets) &&
|
||||
Arrays.equals(wickets, ow.wickets) &&
|
||||
|
||||
Objects.equal(nullWocket1, ow.nullWocket1) &&
|
||||
Arrays.equals(nullWockets, ow.nullWockets) &&
|
||||
Arrays.equals(nullWickets, ow.nullWickets) &&
|
||||
|
||||
Objects.equal(object1, ow.object1) &&
|
||||
Objects.equal(nullObject1, ow.nullObject1) &&
|
||||
Arrays.equals(objects, ow.objects) &&
|
||||
Arrays.equals(nullObjects, ow.nullObjects) &&
|
||||
|
||||
Objects.equal(list, ow.list) &&
|
||||
Objects.equal(nullList, ow.nullList) &&
|
||||
Objects.equal(arrayList, ow.arrayList) &&
|
||||
Objects.equal(nullArrayList, ow.nullArrayList) &&
|
||||
|
||||
Objects.equal(collection, ow.collection) &&
|
||||
Objects.equal(nullCollection, ow.nullCollection) &&
|
||||
|
||||
Objects.equal(set, ow.set) &&
|
||||
Objects.equal(nullSet, ow.nullSet) &&
|
||||
Objects.equal(hashSet, ow.hashSet) &&
|
||||
Objects.equal(nullHashSet, ow.nullHashSet) &&
|
||||
|
||||
Objects.equal(map, ow.map) &&
|
||||
Objects.equal(nullMap, ow.nullMap) &&
|
||||
Objects.equal(hashMap, ow.hashMap) &&
|
||||
Objects.equal(nullHashMap, ow.nullHashMap) &&
|
||||
|
||||
true; // handy end-of-chain
|
||||
}
|
||||
|
||||
@Override
|
||||
public Widget clone ()
|
||||
{
|
||||
try {
|
||||
return (Widget)super.clone();
|
||||
} catch (CloneNotSupportedException cnse) {
|
||||
throw new AssertionError(cnse);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class Wocket extends SimpleStreamableObject
|
||||
{
|
||||
public byte bizyte = 15;
|
||||
public short shizort = Short.MAX_VALUE;
|
||||
public double dizouble = Math.PI;
|
||||
|
||||
@Override
|
||||
public boolean equals (Object other) {
|
||||
if (!(other instanceof Wocket)) {
|
||||
return false;
|
||||
}
|
||||
Wocket ow = (Wocket)other;
|
||||
return bizyte == ow.bizyte &&
|
||||
shizort == ow.shizort &&
|
||||
dizouble == ow.dizouble;
|
||||
}
|
||||
}
|
||||
|
||||
public static final class Wicket extends SimpleStreamableObject
|
||||
{
|
||||
public byte bizyte = 15;
|
||||
public short shizort = Short.MAX_VALUE;
|
||||
public double dizouble = Math.PI;
|
||||
|
||||
public void writeObject (ObjectOutputStream out)
|
||||
throws IOException
|
||||
{
|
||||
out.defaultWriteObject();
|
||||
out.writeInt(_fizzle);
|
||||
}
|
||||
|
||||
public void readObject (ObjectInputStream in)
|
||||
throws IOException, ClassNotFoundException
|
||||
{
|
||||
in.defaultReadObject();
|
||||
_fizzle = in.readInt();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals (Object other) {
|
||||
if (!(other instanceof Wicket)) {
|
||||
return false;
|
||||
}
|
||||
Wicket ow = (Wicket)other;
|
||||
return bizyte == ow.bizyte &&
|
||||
shizort == ow.shizort &&
|
||||
dizouble == ow.dizouble &&
|
||||
_fizzle == ow._fizzle;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void toString (StringBuilder buf)
|
||||
{
|
||||
super.toString(buf);
|
||||
buf.append(", fizzle=").append(_fizzle);
|
||||
}
|
||||
|
||||
protected int _fizzle = 19;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFields ()
|
||||
throws IOException, ClassNotFoundException
|
||||
{
|
||||
Widget w = new Widget();
|
||||
ByteArrayOutputStream bout = new ByteArrayOutputStream();
|
||||
ObjectOutputStream oout = new ObjectOutputStream(bout);
|
||||
oout.writeObject(w);
|
||||
ObjectInputStream oin = new ObjectInputStream(
|
||||
new ByteArrayInputStream(bout.toByteArray()));
|
||||
assertEquals(w, oin.readObject());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWireFormat ()
|
||||
throws IOException, ClassNotFoundException
|
||||
{
|
||||
Widget w = new Widget();
|
||||
|
||||
// make sure that we serialize to the expected stream of bytes
|
||||
ByteArrayOutputStream bout = new ByteArrayOutputStream();
|
||||
ObjectOutputStream oout = new ObjectOutputStream(bout);
|
||||
oout.writeObject(w);
|
||||
byte[] data = bout.toByteArray();
|
||||
|
||||
// uncomment this and rerun the tests to generate an updated WIRE_DATA blob
|
||||
// printWireData(w);
|
||||
|
||||
// oddly, JUnit doesn't like comparing byte arrays directly (this fails:
|
||||
// assertEquals(WIRE_DATA, WIRE_DATA.clone())), but comparing strings is fine
|
||||
assertEquals(StringUtil.hexlate(data), StringUtil.hexlate(WIRE_DATA));
|
||||
|
||||
// make sure that we unserialize a known stream of bytes to the expected object
|
||||
ObjectInputStream oin = new ObjectInputStream(new ByteArrayInputStream(WIRE_DATA));
|
||||
assertEquals(w, oin.readObject());
|
||||
}
|
||||
|
||||
protected void printWireData (Object o)
|
||||
throws IOException
|
||||
{
|
||||
ByteArrayOutputStream bout = new ByteArrayOutputStream();
|
||||
ObjectOutputStream oout = new ObjectOutputStream(bout);
|
||||
oout.writeObject(o);
|
||||
String dstr = StringUtil.wordWrap(StringUtil.hexlate(bout.toByteArray()), 80);
|
||||
dstr = StringUtil.join(dstr.split("\n"), "\" +\n \"");
|
||||
System.out.println(" protected static final byte[] WIRE_DATA = "
|
||||
+ "StringUtil.unhexlate(\n \"" + dstr + "\");");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPostStreamingMutation ()
|
||||
throws IOException, ClassNotFoundException
|
||||
{
|
||||
// create an object graph to be streamed
|
||||
Widget w = new Widget();
|
||||
|
||||
ByteArrayOutputStream bout = new ByteArrayOutputStream();
|
||||
ObjectOutputStream oout = new ObjectOutputStream(bout);
|
||||
Widget w1 = w.clone();
|
||||
oout.writeObject(w);
|
||||
w.string1 = "two";
|
||||
Widget w2 = w.clone();
|
||||
oout.writeObject(w);
|
||||
w.string1 = "three";
|
||||
Widget w3 = w.clone();
|
||||
oout.writeObject(w);
|
||||
Tuple<String,String> tup = StreamableTuple.newTuple("left", "right");
|
||||
oout.writeObject(tup);
|
||||
|
||||
byte[] data = bout.toByteArray();
|
||||
// System.out.println(data.length + " bytes were written.");
|
||||
|
||||
ByteArrayInputStream bin = new ByteArrayInputStream(data);
|
||||
ObjectInputStream oin = new ObjectInputStream(bin);
|
||||
Object ow1 = oin.readObject(); // widget
|
||||
Object ow2 = oin.readObject(); // modified widget
|
||||
Object ow3 = oin.readObject(); // again modified widget
|
||||
Object otup = oin.readObject(); // streamable tuple
|
||||
|
||||
assertEquals(w1, ow1);
|
||||
assertEquals(w2, ow2);
|
||||
assertEquals(w3, ow3);
|
||||
assertEquals(tup, otup);
|
||||
}
|
||||
|
||||
protected static final byte[] WIRE_DATA = StringUtil.unhexlate(
|
||||
"ffff0027636f6d2e746872656572696e67732e696f2e53747265616d61626c655465737424576964" +
|
||||
"676574017f00617fff7fffffff7fffffffffffffff7f7fffff7fefffffffffffff0101017f010061" +
|
||||
"017fff017fffffff017fffffffffffffff017f7fffff017fefffffffffffff000000000000000001" +
|
||||
"00036f6e6500ffff000d6d6f6e6b6579206275747465720000000000000000002a01000100010000" +
|
||||
"000301000101000000037f020301000000037fff0002000301000000030061006200630100000003" +
|
||||
"7fffffff000000020000000301000000037fffffffffffffff000000000000000200000000000000" +
|
||||
"0301000000037f7fffff400000004040000001000000037fefffffffffffff400000000000000040" +
|
||||
"080000000000000000000000000000fffe0027636f6d2e746872656572696e67732e696f2e537472" +
|
||||
"65616d61626c655465737424576f636b65740f7fff400921fb54442d18fffd002a5b4c636f6d2e74" +
|
||||
"6872656572696e67732e696f2e53747265616d61626c655465737424576f636b65743b0000000200" +
|
||||
"020f7fff400921fb54442d1800020f7fff400921fb54442d18fffc002a5b4c636f6d2e7468726565" +
|
||||
"72696e67732e696f2e53747265616d61626c6554657374245769636b65743b000000030001070f7f" +
|
||||
"ff400921fb54442d1800000013000000130f7fff400921fb54442d1800000013000000130f7fff40" +
|
||||
"0921fb54442d18000000130000001300000000000000020f7fff400921fb54442d1800020f7fff40" +
|
||||
"0921fb54442d18010000000200020f7fff400921fb54442d1800020f7fff400921fb54442d180001" +
|
||||
"00000003fffb00116a6176612e6c616e672e496e7465676572000000010005000000020005000000" +
|
||||
"03000100000003000500000003000500000002000500000001000100000003000500000004000500" +
|
||||
"00000500050000000600010000000300050000000600050000000700050000000800010000000300" +
|
||||
"0500000007000500000008000500000009000100000003000500000001fffa00106a6176612e6c61" +
|
||||
"6e672e537472696e6700036f6e650005000000020006000374776f00050000000300060005746872" +
|
||||
"65650001000000030006000374776f000500000002000600036f6e65000500000001000600057468" +
|
||||
"72656500050000000300");
|
||||
}
|
||||
@@ -1,191 +0,0 @@
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
// Narya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2010 Three Rings Design, Inc., All Rights Reserved
|
||||
// http://www.threerings.net/code/narya/
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it
|
||||
// under the terms of the GNU Lesser General Public License as published
|
||||
// by the Free Software Foundation; either version 2.1 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package com.threerings.presents.client;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.samskivert.util.BasicRunQueue;
|
||||
import com.threerings.util.Name;
|
||||
|
||||
import com.threerings.presents.data.TestObject;
|
||||
import com.threerings.presents.dobj.DEvent;
|
||||
import com.threerings.presents.dobj.EventListener;
|
||||
import com.threerings.presents.dobj.MessageEvent;
|
||||
import com.threerings.presents.dobj.ObjectAccessException;
|
||||
import com.threerings.presents.dobj.Subscriber;
|
||||
import com.threerings.presents.net.UsernamePasswordCreds;
|
||||
|
||||
import static com.threerings.presents.Log.log;
|
||||
|
||||
/**
|
||||
* A standalone test client.
|
||||
*/
|
||||
public class TestClient
|
||||
implements SessionObserver, Subscriber<TestObject>, EventListener,
|
||||
TestService.TestOidListener, TestReceiver
|
||||
{
|
||||
public void setClient (Client client)
|
||||
{
|
||||
_client = client;
|
||||
}
|
||||
|
||||
// from interface SessionObserver
|
||||
public void clientWillLogon (Client client)
|
||||
{
|
||||
client.addServiceGroup("test");
|
||||
}
|
||||
|
||||
// from interface SessionObserver
|
||||
public void clientDidLogon (Client client)
|
||||
{
|
||||
log.info("Client did logon [client=" + client + "].");
|
||||
|
||||
// register ourselves as a test notification receiver
|
||||
client.getInvocationDirector().registerReceiver(new TestDecoder(this));
|
||||
|
||||
TestService service = client.requireService(TestService.class);
|
||||
|
||||
// send a test request
|
||||
ArrayList<Integer> three = new ArrayList<Integer>();
|
||||
three.add(3);
|
||||
three.add(4);
|
||||
three.add(5);
|
||||
service.test(client, "one", 2, three, new TestService.TestFuncListener() {
|
||||
public void testSucceeded (String one, int two) {
|
||||
log.info("Got test response [one=" + one + ", two=" + two + "].");
|
||||
}
|
||||
public void requestFailed (String reason) {
|
||||
log.info("Urk! Request failed [reason=" + reason + "].");
|
||||
}
|
||||
});
|
||||
|
||||
// get the test object id
|
||||
service.getTestOid(client, this);
|
||||
}
|
||||
|
||||
// from interface SessionObserver
|
||||
public void clientObjectDidChange (Client client)
|
||||
{
|
||||
log.info("Client object did change [client=" + client + "].");
|
||||
}
|
||||
|
||||
// from interface SessionObserver
|
||||
public void clientDidLogoff (Client client)
|
||||
{
|
||||
log.info("Client did logoff [client=" + client + "].");
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
// from interface Subscriber
|
||||
public void objectAvailable (final TestObject object)
|
||||
{
|
||||
object.addListener(this);
|
||||
log.info("Object available: " + object);
|
||||
object.postMessage("lawl!");
|
||||
|
||||
// try blowing through our message limit
|
||||
for (int tt = 0; tt < 15; tt++) {
|
||||
log.info("Go speed messages, go! " + tt);
|
||||
for (int ii = 0; ii < 2*Client.DEFAULT_MSGS_PER_SECOND; ii++) {
|
||||
object.postMessage("ZOMG!", new Integer(ii));
|
||||
}
|
||||
try {
|
||||
Thread.sleep(1000L);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
// ask for the power
|
||||
TestService service = _client.requireService(TestService.class);
|
||||
service.giveMeThePower(_client, new TestService.ConfirmListener() {
|
||||
public void requestProcessed () {
|
||||
log.info("We have the power!");
|
||||
// now try blowing through our message limit again
|
||||
for (int ii = 0; ii < 8*Client.DEFAULT_MSGS_PER_SECOND; ii++) {
|
||||
object.postMessage("ZOMG!", new Integer(ii));
|
||||
}
|
||||
// and finally shutdown
|
||||
object.postMessage("shutdown");
|
||||
}
|
||||
public void requestFailed (String cause) {
|
||||
log.warning("Dang, no power! " + cause);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// from interface Subscriber
|
||||
public void requestFailed (int oid, ObjectAccessException cause)
|
||||
{
|
||||
log.info("Object unavailable [oid=" + oid +
|
||||
", reason=" + cause + "].");
|
||||
// nothing to do, so might as well logoff
|
||||
_client.logoff(true);
|
||||
}
|
||||
|
||||
// from interface EventListener
|
||||
public void eventReceived (DEvent event)
|
||||
{
|
||||
log.info("Got event [event=" + event + "].");
|
||||
|
||||
if (event instanceof MessageEvent && ((MessageEvent)event).getName().equals("shutdown")) {
|
||||
// request that we log off
|
||||
_client.logoff(true);
|
||||
}
|
||||
}
|
||||
|
||||
// documentation inherited from interface
|
||||
public void gotTestOid (int testOid)
|
||||
{
|
||||
// subscribe to the test object
|
||||
_client.getDObjectManager().subscribeToObject(testOid, this);
|
||||
}
|
||||
|
||||
// documentation inherited from interface
|
||||
public void requestFailed (String reason)
|
||||
{
|
||||
log.info("Urk! Request failed [reason=" + reason + "].");
|
||||
}
|
||||
|
||||
// documentation inherited from interface
|
||||
public void receivedTest (int one, String two)
|
||||
{
|
||||
log.info("Received test notification [one=" + one +
|
||||
", two=" + two + "].");
|
||||
}
|
||||
|
||||
public static void main (String[] args)
|
||||
{
|
||||
TestClient tclient = new TestClient();
|
||||
UsernamePasswordCreds creds =
|
||||
new UsernamePasswordCreds(new Name("test"), "test");
|
||||
BasicRunQueue rqueue = new BasicRunQueue();
|
||||
Client client = new Client(creds, rqueue);
|
||||
tclient.setClient(client);
|
||||
client.addClientObserver(tclient);
|
||||
client.setServer("localhost", Client.DEFAULT_SERVER_PORTS);
|
||||
client.logon();
|
||||
// start up our event processing loop
|
||||
rqueue.run();
|
||||
}
|
||||
|
||||
protected Client _client;
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
// Narya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2010 Three Rings Design, Inc., All Rights Reserved
|
||||
// http://www.threerings.net/code/narya/
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it
|
||||
// under the terms of the GNU Lesser General Public License as published
|
||||
// by the Free Software Foundation; either version 2.1 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package com.threerings.presents.client;
|
||||
|
||||
import com.threerings.presents.client.InvocationDecoder;
|
||||
|
||||
/**
|
||||
* Dispatches calls to a {@link TestReceiver} instance.
|
||||
*/
|
||||
public class TestDecoder extends InvocationDecoder
|
||||
{
|
||||
/** The generated hash code used to identify this receiver class. */
|
||||
public static final String RECEIVER_CODE = "b4b66d24b85d870d04c8da3524c188eb";
|
||||
|
||||
/** The method id used to dispatch {@link TestReceiver#receivedTest}
|
||||
* notifications. */
|
||||
public static final int RECEIVED_TEST = 1;
|
||||
|
||||
/**
|
||||
* Creates a decoder that may be registered to dispatch invocation
|
||||
* service notifications to the specified receiver.
|
||||
*/
|
||||
public TestDecoder (TestReceiver receiver)
|
||||
{
|
||||
this.receiver = receiver;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getReceiverCode ()
|
||||
{
|
||||
return RECEIVER_CODE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispatchNotification (int methodId, Object[] args)
|
||||
{
|
||||
switch (methodId) {
|
||||
case RECEIVED_TEST:
|
||||
((TestReceiver)receiver).receivedTest(
|
||||
((Integer)args[0]).intValue(), (String)args[1]
|
||||
);
|
||||
return;
|
||||
|
||||
default:
|
||||
super.dispatchNotification(methodId, args);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
// Narya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2010 Three Rings Design, Inc., All Rights Reserved
|
||||
// http://www.threerings.net/code/narya/
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it
|
||||
// under the terms of the GNU Lesser General Public License as published
|
||||
// by the Free Software Foundation; either version 2.1 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package com.threerings.presents.client;
|
||||
|
||||
/**
|
||||
* A test of the invocation notification services.
|
||||
*/
|
||||
public interface TestReceiver extends InvocationReceiver
|
||||
{
|
||||
/**
|
||||
* Dispatches a test notification.
|
||||
*/
|
||||
public void receivedTest (int one, String two);
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
// Narya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2010 Three Rings Design, Inc., All Rights Reserved
|
||||
// http://www.threerings.net/code/narya/
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it
|
||||
// under the terms of the GNU Lesser General Public License as published
|
||||
// by the Free Software Foundation; either version 2.1 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package com.threerings.presents.client;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A test of the invocation services.
|
||||
*/
|
||||
public interface TestService extends InvocationService
|
||||
{
|
||||
/** Used to dispatch responses to {@link TestService#test} requests. */
|
||||
public static interface TestFuncListener extends InvocationListener
|
||||
{
|
||||
/** Informs listener of successful {@link TestService#test} request. */
|
||||
public void testSucceeded (String one, int two);
|
||||
}
|
||||
|
||||
/** Used to dispatch responses to {@link TestService#getTestOid} requests. */
|
||||
public static interface TestOidListener extends InvocationListener
|
||||
{
|
||||
/** Communicates test oid to listener. */
|
||||
public void gotTestOid (int testOid);
|
||||
}
|
||||
|
||||
/** Issues a test request. */
|
||||
public void test (Client client, String one, int two, List<Integer> three,
|
||||
TestFuncListener listener);
|
||||
|
||||
/** Issues a request for the test oid. */
|
||||
public void getTestOid (Client client, TestOidListener listener);
|
||||
|
||||
/** Tests upping the client's maximum message rate. */
|
||||
public void giveMeThePower (Client client, ConfirmListener listener);
|
||||
}
|
||||
@@ -1,148 +0,0 @@
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
// Narya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2010 Three Rings Design, Inc., All Rights Reserved
|
||||
// http://www.threerings.net/code/narya/
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it
|
||||
// under the terms of the GNU Lesser General Public License as published
|
||||
// by the Free Software Foundation; either version 2.1 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package com.threerings.presents.data;
|
||||
|
||||
import com.threerings.presents.client.Client;
|
||||
import com.threerings.presents.client.InvocationService;
|
||||
import com.threerings.presents.client.TestService;
|
||||
import com.threerings.presents.dobj.InvocationResponseEvent;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Provides the implementation of the {@link TestService} interface
|
||||
* that marshalls the arguments and delivers the request to the provider
|
||||
* on the server. Also provides an implementation of the response listener
|
||||
* interfaces that marshall the response arguments and deliver them back
|
||||
* to the requesting client.
|
||||
*/
|
||||
public class TestMarshaller extends InvocationMarshaller
|
||||
implements TestService
|
||||
{
|
||||
/**
|
||||
* Marshalls results to implementations of {@link TestService.TestFuncListener}.
|
||||
*/
|
||||
public static class TestFuncMarshaller extends ListenerMarshaller
|
||||
implements TestFuncListener
|
||||
{
|
||||
/** The method id used to dispatch {@link #testSucceeded}
|
||||
* responses. */
|
||||
public static final int TEST_SUCCEEDED = 1;
|
||||
|
||||
// from interface TestFuncMarshaller
|
||||
public void testSucceeded (String arg1, int arg2)
|
||||
{
|
||||
_invId = null;
|
||||
omgr.postEvent(new InvocationResponseEvent(
|
||||
callerOid, requestId, TEST_SUCCEEDED,
|
||||
new Object[] { arg1, Integer.valueOf(arg2) }, transport));
|
||||
}
|
||||
|
||||
@Override // from InvocationMarshaller
|
||||
public void dispatchResponse (int methodId, Object[] args)
|
||||
{
|
||||
switch (methodId) {
|
||||
case TEST_SUCCEEDED:
|
||||
((TestFuncListener)listener).testSucceeded(
|
||||
(String)args[0], ((Integer)args[1]).intValue());
|
||||
return;
|
||||
|
||||
default:
|
||||
super.dispatchResponse(methodId, args);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Marshalls results to implementations of {@link TestService.TestOidListener}.
|
||||
*/
|
||||
public static class TestOidMarshaller extends ListenerMarshaller
|
||||
implements TestOidListener
|
||||
{
|
||||
/** The method id used to dispatch {@link #gotTestOid}
|
||||
* responses. */
|
||||
public static final int GOT_TEST_OID = 1;
|
||||
|
||||
// from interface TestOidMarshaller
|
||||
public void gotTestOid (int arg1)
|
||||
{
|
||||
_invId = null;
|
||||
omgr.postEvent(new InvocationResponseEvent(
|
||||
callerOid, requestId, GOT_TEST_OID,
|
||||
new Object[] { Integer.valueOf(arg1) }, transport));
|
||||
}
|
||||
|
||||
@Override // from InvocationMarshaller
|
||||
public void dispatchResponse (int methodId, Object[] args)
|
||||
{
|
||||
switch (methodId) {
|
||||
case GOT_TEST_OID:
|
||||
((TestOidListener)listener).gotTestOid(
|
||||
((Integer)args[0]).intValue());
|
||||
return;
|
||||
|
||||
default:
|
||||
super.dispatchResponse(methodId, args);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** The method id used to dispatch {@link #getTestOid} requests. */
|
||||
public static final int GET_TEST_OID = 1;
|
||||
|
||||
// from interface TestService
|
||||
public void getTestOid (Client arg1, TestService.TestOidListener arg2)
|
||||
{
|
||||
TestMarshaller.TestOidMarshaller listener2 = new TestMarshaller.TestOidMarshaller();
|
||||
listener2.listener = arg2;
|
||||
sendRequest(arg1, GET_TEST_OID, new Object[] {
|
||||
listener2
|
||||
});
|
||||
}
|
||||
|
||||
/** The method id used to dispatch {@link #giveMeThePower} requests. */
|
||||
public static final int GIVE_ME_THE_POWER = 2;
|
||||
|
||||
// from interface TestService
|
||||
public void giveMeThePower (Client arg1, InvocationService.ConfirmListener arg2)
|
||||
{
|
||||
InvocationMarshaller.ConfirmMarshaller listener2 = new InvocationMarshaller.ConfirmMarshaller();
|
||||
listener2.listener = arg2;
|
||||
sendRequest(arg1, GIVE_ME_THE_POWER, new Object[] {
|
||||
listener2
|
||||
});
|
||||
}
|
||||
|
||||
/** The method id used to dispatch {@link #test} requests. */
|
||||
public static final int TEST = 3;
|
||||
|
||||
// from interface TestService
|
||||
public void test (Client arg1, String arg2, int arg3, List<Integer> arg4, TestService.TestFuncListener arg5)
|
||||
{
|
||||
TestMarshaller.TestFuncMarshaller listener5 = new TestMarshaller.TestFuncMarshaller();
|
||||
listener5.listener = arg5;
|
||||
sendRequest(arg1, TEST, new Object[] {
|
||||
arg2, Integer.valueOf(arg3), arg4, listener5
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,201 +0,0 @@
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
// Narya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2010 Three Rings Design, Inc., All Rights Reserved
|
||||
// http://www.threerings.net/code/narya/
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it
|
||||
// under the terms of the GNU Lesser General Public License as published
|
||||
// by the Free Software Foundation; either version 2.1 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package com.threerings.presents.data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import com.threerings.presents.dobj.DObject;
|
||||
import com.threerings.presents.dobj.OidList;
|
||||
|
||||
/**
|
||||
* A test distributed object.
|
||||
*/
|
||||
public class TestObject extends DObject
|
||||
{
|
||||
// AUTO-GENERATED: FIELDS START
|
||||
/** The field name of the <code>foo</code> field. */
|
||||
public static final String FOO = "foo";
|
||||
|
||||
/** The field name of the <code>bar</code> field. */
|
||||
public static final String BAR = "bar";
|
||||
|
||||
/** The field name of the <code>ints</code> field. */
|
||||
public static final String INTS = "ints";
|
||||
|
||||
/** The field name of the <code>strings</code> field. */
|
||||
public static final String STRINGS = "strings";
|
||||
|
||||
/** The field name of the <code>list</code> field. */
|
||||
public static final String LIST = "list";
|
||||
|
||||
/** The field name of the <code>longs</code> field. */
|
||||
public static final String LONGS = "longs";
|
||||
// AUTO-GENERATED: FIELDS END
|
||||
|
||||
public int foo;
|
||||
|
||||
public String bar;
|
||||
|
||||
public int[] ints = new int[5];
|
||||
|
||||
public String[] strings = new String[5];
|
||||
|
||||
public OidList list = new OidList();
|
||||
|
||||
public ArrayList<Long> longs = new ArrayList<Long>();
|
||||
|
||||
// AUTO-GENERATED: METHODS START
|
||||
/**
|
||||
* Requests that the <code>foo</code> field be set to the
|
||||
* specified value. The local value will be updated immediately and an
|
||||
* event will be propagated through the system to notify all listeners
|
||||
* that the attribute did change. Proxied copies of this object (on
|
||||
* clients) will apply the value change when they received the
|
||||
* attribute changed notification.
|
||||
*/
|
||||
public void setFoo (int value)
|
||||
{
|
||||
int ovalue = this.foo;
|
||||
requestAttributeChange(
|
||||
FOO, Integer.valueOf(value), Integer.valueOf(ovalue));
|
||||
this.foo = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests that the <code>bar</code> field be set to the
|
||||
* specified value. The local value will be updated immediately and an
|
||||
* event will be propagated through the system to notify all listeners
|
||||
* that the attribute did change. Proxied copies of this object (on
|
||||
* clients) will apply the value change when they received the
|
||||
* attribute changed notification.
|
||||
*/
|
||||
public void setBar (String value)
|
||||
{
|
||||
String ovalue = this.bar;
|
||||
requestAttributeChange(
|
||||
BAR, value, ovalue);
|
||||
this.bar = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests that the <code>ints</code> field be set to the
|
||||
* specified value. The local value will be updated immediately and an
|
||||
* event will be propagated through the system to notify all listeners
|
||||
* that the attribute did change. Proxied copies of this object (on
|
||||
* clients) will apply the value change when they received the
|
||||
* attribute changed notification.
|
||||
*/
|
||||
public void setInts (int[] value)
|
||||
{
|
||||
int[] ovalue = this.ints;
|
||||
requestAttributeChange(
|
||||
INTS, value, ovalue);
|
||||
this.ints = (value == null) ? null : (int[])value.clone();
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests that the <code>index</code>th element of
|
||||
* <code>ints</code> field be set to the specified value.
|
||||
* The local value will be updated immediately and an event will be
|
||||
* propagated through the system to notify all listeners that the
|
||||
* attribute did change. Proxied copies of this object (on clients)
|
||||
* will apply the value change when they received the attribute
|
||||
* changed notification.
|
||||
*/
|
||||
public void setIntsAt (int value, int index)
|
||||
{
|
||||
int ovalue = this.ints[index];
|
||||
requestElementUpdate(
|
||||
INTS, index, Integer.valueOf(value), Integer.valueOf(ovalue));
|
||||
this.ints[index] = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests that the <code>strings</code> field be set to the
|
||||
* specified value. The local value will be updated immediately and an
|
||||
* event will be propagated through the system to notify all listeners
|
||||
* that the attribute did change. Proxied copies of this object (on
|
||||
* clients) will apply the value change when they received the
|
||||
* attribute changed notification.
|
||||
*/
|
||||
public void setStrings (String[] value)
|
||||
{
|
||||
String[] ovalue = this.strings;
|
||||
requestAttributeChange(
|
||||
STRINGS, value, ovalue);
|
||||
this.strings = (value == null) ? null : (String[])value.clone();
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests that the <code>index</code>th element of
|
||||
* <code>strings</code> field be set to the specified value.
|
||||
* The local value will be updated immediately and an event will be
|
||||
* propagated through the system to notify all listeners that the
|
||||
* attribute did change. Proxied copies of this object (on clients)
|
||||
* will apply the value change when they received the attribute
|
||||
* changed notification.
|
||||
*/
|
||||
public void setStringsAt (String value, int index)
|
||||
{
|
||||
String ovalue = this.strings[index];
|
||||
requestElementUpdate(
|
||||
STRINGS, index, value, ovalue);
|
||||
this.strings[index] = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests that <code>oid</code> be added to the <code>list</code>
|
||||
* oid list. The list will not change until the event is actually
|
||||
* propagated through the system.
|
||||
*/
|
||||
public void addToList (int oid)
|
||||
{
|
||||
requestOidAdd(LIST, oid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests that <code>oid</code> be removed from the
|
||||
* <code>list</code> oid list. The list will not change until the
|
||||
* event is actually propagated through the system.
|
||||
*/
|
||||
public void removeFromList (int oid)
|
||||
{
|
||||
requestOidRemove(LIST, oid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Requests that the <code>longs</code> field be set to the
|
||||
* specified value. The local value will be updated immediately and an
|
||||
* event will be propagated through the system to notify all listeners
|
||||
* that the attribute did change. Proxied copies of this object (on
|
||||
* clients) will apply the value change when they received the
|
||||
* attribute changed notification.
|
||||
*/
|
||||
public void setLongs (ArrayList<java.lang.Long> value)
|
||||
{
|
||||
ArrayList<java.lang.Long> ovalue = this.longs;
|
||||
requestAttributeChange(
|
||||
LONGS, value, ovalue);
|
||||
this.longs = value;
|
||||
}
|
||||
// AUTO-GENERATED: METHODS END
|
||||
}
|
||||
@@ -1,88 +0,0 @@
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
// Narya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2010 Three Rings Design, Inc., All Rights Reserved
|
||||
// http://www.threerings.net/code/narya/
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it
|
||||
// under the terms of the GNU Lesser General Public License as published
|
||||
// by the Free Software Foundation; either version 2.1 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package com.threerings.presents.dobj;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* Tests the {@link DSet} class.
|
||||
*/
|
||||
public class DSetTest extends TestCase
|
||||
{
|
||||
public static class TestEntry implements DSet.Entry
|
||||
{
|
||||
public TestEntry (int value)
|
||||
{
|
||||
_value = new Integer(value);
|
||||
}
|
||||
|
||||
public Comparable<?> getKey ()
|
||||
{
|
||||
return _value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString ()
|
||||
{
|
||||
return _value.toString();
|
||||
}
|
||||
|
||||
protected Integer _value;
|
||||
}
|
||||
|
||||
public DSetTest ()
|
||||
{
|
||||
super(DSetTest.class.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runTest ()
|
||||
{
|
||||
ArrayList<TestEntry> seed = new ArrayList<TestEntry>();
|
||||
seed.add(new TestEntry(15));
|
||||
seed.add(new TestEntry(7));
|
||||
seed.add(new TestEntry(3));
|
||||
seed.add(new TestEntry(29));
|
||||
seed.add(new TestEntry(32));
|
||||
|
||||
DSet<TestEntry> set = new DSet<TestEntry>(seed.iterator());
|
||||
assertFalse(set.add(new TestEntry(15)));
|
||||
assertTrue(set.add(new TestEntry(9)));
|
||||
assertTrue(set.remove(new TestEntry(32)));
|
||||
assertFalse(set.remove(new TestEntry(32)));
|
||||
assertTrue(set.add(new TestEntry(32)));
|
||||
}
|
||||
|
||||
public static Test suite ()
|
||||
{
|
||||
return new DSetTest();
|
||||
}
|
||||
|
||||
public static void main (String[] args)
|
||||
{
|
||||
DSetTest test = new DSetTest();
|
||||
test.runTest();
|
||||
}
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
//
|
||||
// $Id$
|
||||
|
||||
package com.threerings.presents.dobj;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Tests distributed object local attributes.
|
||||
*/
|
||||
public class LocalAttrTest
|
||||
{
|
||||
public static class BaseLocalAttr
|
||||
{
|
||||
}
|
||||
|
||||
public static class DerivedLocalAttr extends BaseLocalAttr
|
||||
{
|
||||
}
|
||||
|
||||
@Test public void testSetGet ()
|
||||
{
|
||||
DObject o1 = new DObject();
|
||||
BaseLocalAttr base = new BaseLocalAttr();
|
||||
o1.setLocal(BaseLocalAttr.class, base);
|
||||
assertSame(o1.getLocal(BaseLocalAttr.class), base);
|
||||
}
|
||||
|
||||
@Test public void testPoly ()
|
||||
{
|
||||
// polymorphic usage
|
||||
DObject o2 = new DObject();
|
||||
DerivedLocalAttr derived = new DerivedLocalAttr();
|
||||
o2.setLocal(DerivedLocalAttr.class, derived);
|
||||
BaseLocalAttr upcasted = derived;
|
||||
assertSame(o2.getLocal(DerivedLocalAttr.class), derived);
|
||||
assertSame(o2.getLocal(BaseLocalAttr.class), upcasted);
|
||||
|
||||
// cannot overwrite already set attribute
|
||||
DObject o3 = new DObject();
|
||||
o3.setLocal(DerivedLocalAttr.class, derived);
|
||||
try {
|
||||
o3.setLocal(DerivedLocalAttr.class, new DerivedLocalAttr());
|
||||
fail("Object allowed attribute overwrite.");
|
||||
} catch (IllegalStateException ise) {
|
||||
// good
|
||||
}
|
||||
try {
|
||||
o3.setLocal(BaseLocalAttr.class, new BaseLocalAttr());
|
||||
fail("Object allowed polymorhic attribute overwrite.");
|
||||
} catch (IllegalStateException ise) {
|
||||
// good
|
||||
}
|
||||
}
|
||||
|
||||
@Test public void testSetClearSet ()
|
||||
{
|
||||
DObject o1 = new DObject();
|
||||
BaseLocalAttr base = new BaseLocalAttr();
|
||||
o1.setLocal(BaseLocalAttr.class, base);
|
||||
assertSame(o1.getLocal(BaseLocalAttr.class), base);
|
||||
o1.setLocal(BaseLocalAttr.class, null);
|
||||
assertNull(o1.getLocal(BaseLocalAttr.class));
|
||||
BaseLocalAttr nbase = new BaseLocalAttr();
|
||||
o1.setLocal(BaseLocalAttr.class, nbase);
|
||||
assertNotSame(o1.getLocal(BaseLocalAttr.class), base);
|
||||
assertSame(o1.getLocal(BaseLocalAttr.class), nbase);
|
||||
}
|
||||
}
|
||||
@@ -1,101 +0,0 @@
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
// Narya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2010 Three Rings Design, Inc., All Rights Reserved
|
||||
// http://www.threerings.net/code/narya/
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it
|
||||
// under the terms of the GNU Lesser General Public License as published
|
||||
// by the Free Software Foundation; either version 2.1 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package com.threerings.presents.server;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.threerings.presents.data.TestObject;
|
||||
import com.threerings.presents.dobj.AttributeChangeListener;
|
||||
import com.threerings.presents.dobj.AttributeChangedEvent;
|
||||
import com.threerings.presents.dobj.ElementUpdateListener;
|
||||
import com.threerings.presents.dobj.ElementUpdatedEvent;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* A simple test case for the dobjmgr.
|
||||
*/
|
||||
public class DOMTest extends PresentsTestBase
|
||||
implements AttributeChangeListener, ElementUpdateListener
|
||||
{
|
||||
@Test public void runTest ()
|
||||
{
|
||||
// request that a new TestObject be registered
|
||||
_test = _omgr.registerObject(new TestObject());
|
||||
|
||||
// add ourselves as a listener
|
||||
_test.addListener(this);
|
||||
|
||||
// test transactions
|
||||
_test.startTransaction();
|
||||
_test.setFoo(99);
|
||||
_test.setBar("hoopie");
|
||||
_test.commitTransaction();
|
||||
|
||||
// set some elements
|
||||
_test.setIntsAt(15, 3);
|
||||
_test.setIntsAt(5, 2);
|
||||
_test.setIntsAt(1, 0);
|
||||
_test.setStringsAt("Hello", 0);
|
||||
_test.setStringsAt("Goodbye", 1);
|
||||
_test.setStringsAt(null, 1);
|
||||
|
||||
// now set some values straight up
|
||||
_test.setFoo(25);
|
||||
_test.setBar("howdy");
|
||||
|
||||
// and run the object manager
|
||||
_omgr.run();
|
||||
}
|
||||
|
||||
// from interface AttributeChangeListener
|
||||
public void attributeChanged (AttributeChangedEvent event)
|
||||
{
|
||||
assertTrue(fields[_fcount] + " == " + values[_fcount],
|
||||
event.getName().equals(fields[_fcount]) &&
|
||||
event.getValue().equals(values[_fcount]));
|
||||
|
||||
// shutdown once we receive our last update
|
||||
if (++_fcount == fields.length) {
|
||||
_omgr.harshShutdown();
|
||||
}
|
||||
}
|
||||
|
||||
// from interface ElementUpdateListener
|
||||
public void elementUpdated (ElementUpdatedEvent event)
|
||||
{
|
||||
// Log.info("Element updated " + event);
|
||||
// Log.info(StringUtil.toString(_test.ints));
|
||||
// Log.info(StringUtil.toString(_test.strings));
|
||||
}
|
||||
|
||||
protected int _fcount = 0;
|
||||
protected TestObject _test;
|
||||
|
||||
// the fields that will change in attribute changed events
|
||||
protected Object[] fields = { TestObject.FOO, TestObject.BAR, TestObject.FOO, TestObject.BAR };
|
||||
|
||||
// the values we'll receive via attribute changed events
|
||||
protected Object[] values = { new Integer(99), "hoopie", new Integer(25), "howdy" };
|
||||
|
||||
protected PresentsDObjectMgr _omgr = getInstance(PresentsDObjectMgr.class);
|
||||
}
|
||||
@@ -1,95 +0,0 @@
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
// Narya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2010 Three Rings Design, Inc., All Rights Reserved
|
||||
// http://www.threerings.net/code/narya/
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it
|
||||
// under the terms of the GNU Lesser General Public License as published
|
||||
// by the Free Software Foundation; either version 2.1 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package com.threerings.presents.server;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.threerings.presents.data.TestObject;
|
||||
import com.threerings.presents.dobj.AttributeChangedEvent;
|
||||
import com.threerings.presents.dobj.DEvent;
|
||||
import com.threerings.presents.dobj.EventListener;
|
||||
import com.threerings.presents.dobj.ObjectAddedEvent;
|
||||
import com.threerings.presents.dobj.ObjectDestroyedEvent;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import static com.threerings.presents.Log.log;
|
||||
|
||||
/**
|
||||
* Tests that the dobjmgr will not allow a destroyed object to be added to an oid list.
|
||||
*/
|
||||
public class DestroyedRefTest extends PresentsTestBase
|
||||
{
|
||||
@Test public void runTest ()
|
||||
{
|
||||
// create two test objects
|
||||
_objone = _omgr.registerObject(new TestObject());
|
||||
_objone.addListener(_listener);
|
||||
_objtwo = _omgr.registerObject(new TestObject());
|
||||
_objtwo.addListener(_listener);
|
||||
|
||||
// add object one to object two twice in a row to make sure repeated
|
||||
// adds don't result in the object being listed twice
|
||||
_objtwo.addToList(_objone.getOid());
|
||||
log.info("The following addToList() should be ignored.");
|
||||
_objtwo.addToList(_objone.getOid());
|
||||
|
||||
// now that we have both objects, try to set up the reference. first we queue up a destroy
|
||||
// event for object two, then we try to reference it on object one's oid list
|
||||
_objtwo.destroy();
|
||||
_objone.addToList(_objtwo.getOid());
|
||||
|
||||
// finally dispatch an event on which we can trigger our exit
|
||||
_objone.setFoo(1);
|
||||
|
||||
// and run the object manager
|
||||
_omgr.run();
|
||||
}
|
||||
|
||||
protected EventListener _listener = new EventListener() {
|
||||
public void eventReceived (DEvent event) {
|
||||
int toid = event.getTargetOid();
|
||||
|
||||
// when we get the attribute change, we can exit
|
||||
if (event instanceof ObjectDestroyedEvent) {
|
||||
log.info("The upcoming object added event should be rejected.");
|
||||
|
||||
} else if (event instanceof ObjectAddedEvent &&
|
||||
toid == _objtwo.getOid()) {
|
||||
assertTrue("list should contain only one oid",
|
||||
_objtwo.list.size() == 1);
|
||||
|
||||
} else if (event instanceof AttributeChangedEvent) {
|
||||
// go bye bye
|
||||
_omgr.harshShutdown();
|
||||
|
||||
} else {
|
||||
fail("Got unexpected event: " + event);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
protected TestObject _objone, _objtwo;
|
||||
|
||||
protected PresentsDObjectMgr _omgr = getInstance(PresentsDObjectMgr.class);
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
//
|
||||
// $Id$
|
||||
|
||||
package com.threerings.presents.server;
|
||||
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Tests our handling of auto-canceling intervals created by the omgr if they expire after it has
|
||||
* shutdown.
|
||||
*/
|
||||
public class OMgrIntervalTest extends PresentsTestBase
|
||||
{
|
||||
@Test public void testIntervals ()
|
||||
{
|
||||
final PresentsDObjectMgr omgr = getInstance(PresentsDObjectMgr.class);
|
||||
|
||||
omgr.newInterval(new Runnable () {
|
||||
public void run () {
|
||||
if (++_count > 1) {
|
||||
omgr.harshShutdown();
|
||||
}
|
||||
}
|
||||
}).schedule(100, true);
|
||||
|
||||
omgr.run();
|
||||
|
||||
try {
|
||||
Thread.sleep(500);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
assertTrue(_count == 2);
|
||||
}
|
||||
|
||||
protected int _count;
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
//
|
||||
// $Id$
|
||||
|
||||
package com.threerings.presents.server;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
/**
|
||||
* Sets up Guice so that presents things can be tested.
|
||||
*/
|
||||
public class PresentsTestBase
|
||||
{
|
||||
protected <T> T getInstance (Class<T> clazz)
|
||||
{
|
||||
if (_injector == null) {
|
||||
_injector = Guice.createInjector(new PresentsServer.Module());
|
||||
}
|
||||
return _injector.getInstance(clazz);
|
||||
}
|
||||
|
||||
protected Injector _injector;
|
||||
}
|
||||
@@ -1,91 +0,0 @@
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
// Narya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2010 Three Rings Design, Inc., All Rights Reserved
|
||||
// http://www.threerings.net/code/narya/
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it
|
||||
// under the terms of the GNU Lesser General Public License as published
|
||||
// by the Free Software Foundation; either version 2.1 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package com.threerings.presents.server;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.threerings.presents.data.TestObject;
|
||||
import com.threerings.presents.dobj.DEvent;
|
||||
import com.threerings.presents.dobj.EventListener;
|
||||
import com.threerings.presents.dobj.ObjectAddedEvent;
|
||||
import com.threerings.presents.dobj.ObjectDestroyedEvent;
|
||||
import com.threerings.presents.dobj.ObjectRemovedEvent;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Tests the oid list reference tracking code.
|
||||
*/
|
||||
public class RefTest extends PresentsTestBase
|
||||
{
|
||||
@Test public void runTest ()
|
||||
{
|
||||
// create two test objects
|
||||
_objone = _omgr.registerObject(new TestObject());
|
||||
_objone.addListener(_listener);
|
||||
_objtwo = _omgr.registerObject(new TestObject());
|
||||
_objtwo.addListener(_listener);
|
||||
|
||||
// now that we have both objects, set up the references
|
||||
_objone.addToList(_objtwo.getOid());
|
||||
_objtwo.addToList(_objone.getOid());
|
||||
|
||||
// and run the object manager
|
||||
_omgr.run();
|
||||
}
|
||||
|
||||
protected EventListener _listener = new EventListener() {
|
||||
public void eventReceived (DEvent event) {
|
||||
// Log.info("Got event: " + event);
|
||||
int toid = event.getTargetOid();
|
||||
|
||||
// once we receive the second object added we can destroy the
|
||||
// target object to see if the reference is cleaned up
|
||||
if (event instanceof ObjectAddedEvent &&
|
||||
toid == _objtwo.getOid()) {
|
||||
// Log.info("Destroying object two " + _objtwo + ".");
|
||||
_objtwo.destroy();
|
||||
|
||||
} else if (event instanceof ObjectDestroyedEvent) {
|
||||
if (toid == _objtwo.getOid()) {
|
||||
// Log.info("List won't yet be empty: " + _objone.list);
|
||||
assertTrue("List not empty", _objone.list.size() > 0);
|
||||
} else {
|
||||
// Log.info("Other object destroyed.");
|
||||
// go bye bye
|
||||
_omgr.harshShutdown();
|
||||
}
|
||||
|
||||
} else if (event instanceof ObjectRemovedEvent) {
|
||||
// Log.info("List should be empty: " + _objone.list);
|
||||
assertTrue("List empty", _objone.list.size() == 0);
|
||||
// finally destroy the other object to complete the circle
|
||||
_objone.destroy();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
protected TestObject _objone;
|
||||
protected TestObject _objtwo;
|
||||
|
||||
protected PresentsDObjectMgr _omgr = getInstance(PresentsDObjectMgr.class);
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
// Narya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2010 Three Rings Design, Inc., All Rights Reserved
|
||||
// http://www.threerings.net/code/narya/
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it
|
||||
// under the terms of the GNU Lesser General Public License as published
|
||||
// by the Free Software Foundation; either version 2.1 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package com.threerings.presents.server;
|
||||
|
||||
import com.threerings.presents.client.InvocationService;
|
||||
import com.threerings.presents.client.TestService;
|
||||
import com.threerings.presents.data.ClientObject;
|
||||
import com.threerings.presents.data.TestMarshaller;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Dispatches requests to the {@link TestProvider}.
|
||||
*/
|
||||
public class TestDispatcher extends InvocationDispatcher<TestMarshaller>
|
||||
{
|
||||
/**
|
||||
* Creates a dispatcher that may be registered to dispatch invocation
|
||||
* service requests for the specified provider.
|
||||
*/
|
||||
public TestDispatcher (TestProvider provider)
|
||||
{
|
||||
this.provider = provider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TestMarshaller createMarshaller ()
|
||||
{
|
||||
return new TestMarshaller();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispatchRequest (
|
||||
ClientObject source, int methodId, Object[] args)
|
||||
throws InvocationException
|
||||
{
|
||||
switch (methodId) {
|
||||
case TestMarshaller.GET_TEST_OID:
|
||||
((TestProvider)provider).getTestOid(
|
||||
source, (TestService.TestOidListener)args[0]
|
||||
);
|
||||
return;
|
||||
|
||||
case TestMarshaller.GIVE_ME_THE_POWER:
|
||||
((TestProvider)provider).giveMeThePower(
|
||||
source, (InvocationService.ConfirmListener)args[0]
|
||||
);
|
||||
return;
|
||||
|
||||
case TestMarshaller.TEST:
|
||||
@SuppressWarnings("unchecked") List<Integer> list = (List<Integer>)args[2];
|
||||
((TestProvider)provider).test(
|
||||
source, (String)args[0], ((Integer)args[1]).intValue(), list, (TestService.TestFuncListener)args[3]
|
||||
);
|
||||
return;
|
||||
|
||||
default:
|
||||
super.dispatchRequest(source, methodId, args);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
//
|
||||
// $Id$
|
||||
|
||||
package com.threerings.presents.server;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import com.threerings.presents.client.TestService;
|
||||
import com.threerings.presents.data.ClientObject;
|
||||
import com.threerings.presents.server.ClientManager;
|
||||
|
||||
import static com.threerings.presents.Log.log;
|
||||
|
||||
/**
|
||||
* Implements the server side of the TestProvider interface.
|
||||
*/
|
||||
public class TestManager
|
||||
implements TestProvider
|
||||
{
|
||||
// from interface TestProvider
|
||||
public void getTestOid (ClientObject caller,
|
||||
TestService.TestOidListener listener)
|
||||
throws InvocationException
|
||||
{
|
||||
log.info("Handling get test oid [src=" + caller + "].");
|
||||
|
||||
// issue a test notification just for kicks
|
||||
TestSender.sendTest(caller, 1, "two");
|
||||
|
||||
listener.gotTestOid(TestServer.testobj.getOid());
|
||||
}
|
||||
|
||||
// from interface TestProvider
|
||||
public void test (ClientObject caller, String one, int two, List<Integer> three,
|
||||
TestService.TestFuncListener listener)
|
||||
throws InvocationException
|
||||
{
|
||||
log.info("Test request", "one", one, "two", two, "three", three);
|
||||
|
||||
// and issue a response to this invocation request
|
||||
listener.testSucceeded(one, two);
|
||||
}
|
||||
|
||||
// from interface TestProvider
|
||||
public void giveMeThePower (ClientObject caller, TestService.ConfirmListener listener)
|
||||
{
|
||||
log.info("Giving " + caller.who() + " the power!");
|
||||
_clmgr.getClient(caller.username).setIncomingMessageThrottle(20);
|
||||
listener.requestProcessed();
|
||||
}
|
||||
|
||||
@Inject protected ClientManager _clmgr;
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
// Narya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2010 Three Rings Design, Inc., All Rights Reserved
|
||||
// http://www.threerings.net/code/narya/
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it
|
||||
// under the terms of the GNU Lesser General Public License as published
|
||||
// by the Free Software Foundation; either version 2.1 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package com.threerings.presents.server;
|
||||
|
||||
import com.threerings.presents.client.InvocationService;
|
||||
import com.threerings.presents.client.TestService;
|
||||
import com.threerings.presents.data.ClientObject;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Defines the server-side of the {@link TestService}.
|
||||
*/
|
||||
public interface TestProvider extends InvocationProvider
|
||||
{
|
||||
/**
|
||||
* Handles a {@link TestService#getTestOid} request.
|
||||
*/
|
||||
void getTestOid (ClientObject caller, TestService.TestOidListener arg1)
|
||||
throws InvocationException;
|
||||
|
||||
/**
|
||||
* Handles a {@link TestService#giveMeThePower} request.
|
||||
*/
|
||||
void giveMeThePower (ClientObject caller, InvocationService.ConfirmListener arg1)
|
||||
throws InvocationException;
|
||||
|
||||
/**
|
||||
* Handles a {@link TestService#test} request.
|
||||
*/
|
||||
void test (ClientObject caller, String arg1, int arg2, List<Integer> arg3, TestService.TestFuncListener arg4)
|
||||
throws InvocationException;
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
// Narya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2010 Three Rings Design, Inc., All Rights Reserved
|
||||
// http://www.threerings.net/code/narya/
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it
|
||||
// under the terms of the GNU Lesser General Public License as published
|
||||
// by the Free Software Foundation; either version 2.1 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package com.threerings.presents.server;
|
||||
|
||||
import com.threerings.presents.client.TestDecoder;
|
||||
import com.threerings.presents.client.TestReceiver;
|
||||
import com.threerings.presents.data.ClientObject;
|
||||
import com.threerings.presents.server.InvocationSender;
|
||||
|
||||
/**
|
||||
* Used to issue notifications to a {@link TestReceiver} instance on a
|
||||
* client.
|
||||
*/
|
||||
public class TestSender extends InvocationSender
|
||||
{
|
||||
/**
|
||||
* Issues a notification that will result in a call to {@link
|
||||
* TestReceiver#receivedTest} on a client.
|
||||
*/
|
||||
public static void sendTest (
|
||||
ClientObject target, int arg1, String arg2)
|
||||
{
|
||||
sendNotification(
|
||||
target, TestDecoder.RECEIVER_CODE, TestDecoder.RECEIVED_TEST,
|
||||
new Object[] { Integer.valueOf(arg1), arg2 });
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
// Narya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2010 Three Rings Design, Inc., All Rights Reserved
|
||||
// http://www.threerings.net/code/narya/
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it
|
||||
// under the terms of the GNU Lesser General Public License as published
|
||||
// by the Free Software Foundation; either version 2.1 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package com.threerings.presents.server;
|
||||
|
||||
import com.google.inject.Guice;
|
||||
import com.google.inject.Injector;
|
||||
|
||||
import com.threerings.presents.data.TestObject;
|
||||
|
||||
import static com.threerings.presents.Log.log;
|
||||
|
||||
public class TestServer extends PresentsServer
|
||||
{
|
||||
public static TestObject testobj;
|
||||
|
||||
@Override
|
||||
public void init (Injector injector)
|
||||
throws Exception
|
||||
{
|
||||
super.init(injector);
|
||||
|
||||
// register our test provider
|
||||
_invmgr.registerDispatcher(
|
||||
new TestDispatcher(injector.getInstance(TestManager.class)), "test");
|
||||
|
||||
// create a test object
|
||||
testobj = _omgr.registerObject(new TestObject());
|
||||
testobj.longs.add(System.currentTimeMillis());
|
||||
long value = Integer.MAX_VALUE;
|
||||
value++;
|
||||
testobj.longs.add(value);
|
||||
}
|
||||
|
||||
public static void main (String[] args)
|
||||
{
|
||||
Injector injector = Guice.createInjector(new Module());
|
||||
TestServer server = injector.getInstance(TestServer.class);
|
||||
try {
|
||||
server.init(injector);
|
||||
server.run();
|
||||
} catch (Exception e) {
|
||||
log.warning("Unable to initialize server.", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,93 +0,0 @@
|
||||
//
|
||||
// $Id$
|
||||
//
|
||||
// Narya library - tools for developing networked games
|
||||
// Copyright (C) 2002-2010 Three Rings Design, Inc., All Rights Reserved
|
||||
// http://www.threerings.net/code/narya/
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify it
|
||||
// under the terms of the GNU Lesser General Public License as published
|
||||
// by the Free Software Foundation; either version 2.1 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
package com.threerings.util;
|
||||
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* Tests the {@link MessageBundle} class.
|
||||
*/
|
||||
public class MessageBundleTest extends TestCase
|
||||
{
|
||||
public MessageBundleTest ()
|
||||
{
|
||||
super(MessageBundleTest.class.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runTest ()
|
||||
{
|
||||
try {
|
||||
String path = "rsrc.i18n.messages";
|
||||
ResourceBundle rbundle = ResourceBundle.getBundle(path);
|
||||
MessageBundle bundle = new MessageBundle();
|
||||
bundle.init(null, "test", rbundle, null);
|
||||
|
||||
String key1 = MessageBundle.compose("m.foo",
|
||||
MessageBundle.taint("bar"),
|
||||
MessageBundle.taint("baz"));
|
||||
String key2 = MessageBundle.compose("m.biff",
|
||||
MessageBundle.taint("beep"),
|
||||
MessageBundle.taint("boop"));
|
||||
String key = MessageBundle.compose("m.meta", key1, key2);
|
||||
|
||||
String output = bundle.xlate(key);
|
||||
if (!OUTPUT.equals(output)) {
|
||||
fail("xlate failed: " + output);
|
||||
}
|
||||
|
||||
// Counting sheep
|
||||
assertEquals("No sheep",
|
||||
bundle.xlate(MessageBundle.compose("m.sheep", MessageBundle.taint(0))));
|
||||
assertEquals("One sheep",
|
||||
bundle.xlate(MessageBundle.compose("m.sheep", MessageBundle.taint(1))));
|
||||
assertEquals("666 sheeps",
|
||||
bundle.xlate(MessageBundle.compose("m.sheep", MessageBundle.taint("666"))));
|
||||
assertEquals("Don't suffix me",
|
||||
bundle.xlate(MessageBundle.compose("m.sheep", MessageBundle.taint("zzz"))));
|
||||
|
||||
assertEquals("7x12", bundle.xlate(MessageBundle.compose("m.coord",
|
||||
MessageBundle.taint(7), MessageBundle.taint(12))));
|
||||
|
||||
} catch (Exception e) {
|
||||
fail("Test failed: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
public static Test suite ()
|
||||
{
|
||||
return new MessageBundleTest();
|
||||
}
|
||||
|
||||
public static void main (String[] args)
|
||||
{
|
||||
MessageBundleTest test = new MessageBundleTest();
|
||||
test.runTest();
|
||||
}
|
||||
|
||||
protected static final String OUTPUT =
|
||||
"Meta arg one is 'Foo arg one is 'bar' and two is 'baz'.' and " +
|
||||
"two is 'Biff arg one is 'beep' and two is 'boop'.'.";
|
||||
}
|
||||
Reference in New Issue
Block a user