Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2012-01-14 10:27:01 +0000
committerEike Stepper2012-01-14 10:27:01 +0000
commit0266166cb9ff9535c150250073ea1e57b42d2693 (patch)
treec006a3bc0ba1f6e1d8a2bc032eedc346f71eab0d /plugins/org.eclipse.net4j.tests
parent7416443692cdda72d1f704ea4fc5ececcc669df7 (diff)
downloadcdo-0266166cb9ff9535c150250073ea1e57b42d2693.tar.gz
cdo-0266166cb9ff9535c150250073ea1e57b42d2693.tar.xz
cdo-0266166cb9ff9535c150250073ea1e57b42d2693.zip
Adjusted copyrights to 2012
Diffstat (limited to 'plugins/org.eclipse.net4j.tests')
-rw-r--r--plugins/org.eclipse.net4j.tests/.settings/org.eclipse.core.resources.prefs2
-rw-r--r--plugins/org.eclipse.net4j.tests/.settings/org.eclipse.jdt.ui.prefs240
-rw-r--r--plugins/org.eclipse.net4j.tests/about.properties62
-rw-r--r--plugins/org.eclipse.net4j.tests/build.properties58
-rw-r--r--plugins/org.eclipse.net4j.tests/copyright.txt14
-rw-r--r--plugins/org.eclipse.net4j.tests/model/TestDef.genmodel2
-rw-r--r--plugins/org.eclipse.net4j.tests/plugin.properties22
-rw-r--r--plugins/org.eclipse.net4j.tests/plugin.xml48
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/AbstractProtocolTest.java64
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/AbstractTransportTest.java408
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/AllSSLTests.java74
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/AllTests.java154
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/BufferPoolTest.java194
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/ChannelTest.java742
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/ExceptionTest.java334
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/SelectorTest.java74
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/SignalMonitorTest.java436
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/SignalStreamWrappingTest.java176
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/SignalTest.java350
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/TCPConnectorTest.java1274
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/TCPUnitTest.java54
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/TransportTest.java1068
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/apps/Performance.java288
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/apps/TCPConnectivityLoss.java204
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/bugzilla/Bugzilla_241463_Test.java424
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/bugzilla/Bugzilla_262875_Test.java420
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/bundle/OM.java88
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/data/HugeData.java490
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/data/TinyData.java82
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/defs/JVMAcceptorDefImplTest.java190
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/defs/JVMConnectorDefImplTest.java160
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/defs/TCPAcceptorDefImplTest.java226
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/defs/TCPConnectorDefImplTest.java252
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/defs/Util.java276
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/ArrayIndication.java80
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/ArrayRequest.java84
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/AsyncIndication.java78
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/AsyncRequest.java70
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/ExceptionIndication.java114
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/ExceptionRequest.java108
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/IntFailIndication.java90
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/IntFailRequest.java82
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/IntIndication.java80
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/IntRequest.java82
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/StringIndication.java80
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/StringRequest.java84
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/TestSignalProtocol.java240
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/AbstractOMTest.java1544
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/ConcurrentRunner.java280
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/ExpectedIOTest.java780
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/ExtendedIOTest.java314
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/FastListTest.java588
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/MonitorTest.java604
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/MultiMapTest.java582
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/OMTest.java94
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/QueueWorkerWorkSerializerTest.java432
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/ReferenceValueMapTest.java86
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/SecurityTest.java482
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/SortedFileMapTest.java216
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/StreamWrapperTest.java92
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/StringCompressorTest.java582
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/SynchronizingCorrelatorTest.java302
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/UTFTest.java130
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/UUIDGeneratorTest.java2
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/ZipTest.java68
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/cache/CacheTest.java108
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/cache/Revision.java134
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/cache/RevisionManager.java294
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/cache/SensitiveProtoTest.java168
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/defs/DefsFactory.java96
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/defs/DefsPackage.java362
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/defs/TestDef.java154
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/defs/TestDefTest.java522
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/defs/TestDefsFactory.java96
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/defs/TestDefsPackage.java362
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/defs/impl/DefsFactoryImpl.java228
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/defs/impl/DefsPackageImpl.java452
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/defs/impl/TestDefImpl.java472
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/defs/impl/TestDefsFactoryImpl.java228
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/defs/impl/TestDefsPackageImpl.java444
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/defs/util/DefsAdapterFactory.java308
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/defs/util/DefsSwitch.java324
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/defs/util/TestDefsAdapterFactory.java308
-rw-r--r--plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/defs/util/TestDefsSwitch.java324
84 files changed, 11392 insertions, 11392 deletions
diff --git a/plugins/org.eclipse.net4j.tests/.settings/org.eclipse.core.resources.prefs b/plugins/org.eclipse.net4j.tests/.settings/org.eclipse.core.resources.prefs
index f9589dba61..230da2dabf 100644
--- a/plugins/org.eclipse.net4j.tests/.settings/org.eclipse.core.resources.prefs
+++ b/plugins/org.eclipse.net4j.tests/.settings/org.eclipse.core.resources.prefs
@@ -1,3 +1,3 @@
-#Mon Jul 04 13:02:59 CEST 2011
eclipse.preferences.version=1
+encoding//model/TestDef.genmodel=UTF-8
encoding//model/org.eclipse.emf.cdo.defs.ecorediag=UTF-8
diff --git a/plugins/org.eclipse.net4j.tests/.settings/org.eclipse.jdt.ui.prefs b/plugins/org.eclipse.net4j.tests/.settings/org.eclipse.jdt.ui.prefs
index aaef0ccba1..6726e7034a 100644
--- a/plugins/org.eclipse.net4j.tests/.settings/org.eclipse.jdt.ui.prefs
+++ b/plugins/org.eclipse.net4j.tests/.settings/org.eclipse.jdt.ui.prefs
@@ -1,120 +1,120 @@
-#Thu Feb 04 09:44:24 CET 2010
-cleanup.add_default_serial_version_id=true
-cleanup.add_generated_serial_version_id=false
-cleanup.add_missing_annotations=true
-cleanup.add_missing_deprecated_annotations=true
-cleanup.add_missing_methods=false
-cleanup.add_missing_nls_tags=false
-cleanup.add_missing_override_annotations=true
-cleanup.add_missing_override_annotations_interface_methods=true
-cleanup.add_serial_version_id=true
-cleanup.always_use_blocks=true
-cleanup.always_use_parentheses_in_expressions=false
-cleanup.always_use_this_for_non_static_field_access=false
-cleanup.always_use_this_for_non_static_method_access=false
-cleanup.convert_to_enhanced_for_loop=false
-cleanup.correct_indentation=true
-cleanup.format_source_code=true
-cleanup.format_source_code_changes_only=false
-cleanup.make_local_variable_final=true
-cleanup.make_parameters_final=false
-cleanup.make_private_fields_final=true
-cleanup.make_type_abstract_if_missing_method=false
-cleanup.make_variable_declarations_final=false
-cleanup.never_use_blocks=false
-cleanup.never_use_parentheses_in_expressions=true
-cleanup.organize_imports=true
-cleanup.qualify_static_field_accesses_with_declaring_class=false
-cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
-cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
-cleanup.qualify_static_member_accesses_with_declaring_class=false
-cleanup.qualify_static_method_accesses_with_declaring_class=false
-cleanup.remove_private_constructors=true
-cleanup.remove_trailing_whitespaces=true
-cleanup.remove_trailing_whitespaces_all=true
-cleanup.remove_trailing_whitespaces_ignore_empty=false
-cleanup.remove_unnecessary_casts=true
-cleanup.remove_unnecessary_nls_tags=true
-cleanup.remove_unused_imports=true
-cleanup.remove_unused_local_variables=false
-cleanup.remove_unused_private_fields=true
-cleanup.remove_unused_private_members=false
-cleanup.remove_unused_private_methods=true
-cleanup.remove_unused_private_types=true
-cleanup.sort_members=false
-cleanup.sort_members_all=false
-cleanup.use_blocks=true
-cleanup.use_blocks_only_for_return_and_throw=false
-cleanup.use_parentheses_in_expressions=true
-cleanup.use_this_for_non_static_field_access=true
-cleanup.use_this_for_non_static_field_access_only_if_necessary=true
-cleanup.use_this_for_non_static_method_access=true
-cleanup.use_this_for_non_static_method_access_only_if_necessary=true
-cleanup_profile=_EMFT
-cleanup_settings_version=2
-eclipse.preferences.version=1
-editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
-formatter_profile=_EMFT
-formatter_settings_version=11
-org.eclipse.jdt.ui.exception.name=ex
-org.eclipse.jdt.ui.gettersetter.use.is=true
-org.eclipse.jdt.ui.ignorelowercasenames=true
-org.eclipse.jdt.ui.importorder=org.eclipse.emf.cdo;org.eclipse.emf.internal.cdo;org.eclipse.net4j;org.eclipse.internal.net4j;org.eclipse.emf;org.eclipse;com;org;javax;java;
-org.eclipse.jdt.ui.javadoc=true
-org.eclipse.jdt.ui.keywordthis=false
-org.eclipse.jdt.ui.ondemandthreshold=99
-org.eclipse.jdt.ui.overrideannotation=true
-org.eclipse.jdt.ui.staticondemandthreshold=99
-org.eclipse.jdt.ui.text.custom_code_templates=<?xml version\="1.0" encoding\="UTF-8" standalone\="no"?><templates><template autoinsert\="false" context\="gettercomment_context" deleted\="false" description\="Comment for getter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.gettercomment" name\="gettercomment"/><template autoinsert\="false" context\="settercomment_context" deleted\="false" description\="Comment for setter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.settercomment" name\="settercomment"/><template autoinsert\="false" context\="constructorcomment_context" deleted\="false" description\="Comment for created constructors" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorcomment" name\="constructorcomment"/><template autoinsert\="false" context\="filecomment_context" deleted\="false" description\="Comment for created Java files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.filecomment" name\="filecomment">/*\r\n * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.\r\n * All rights reserved. This program and the accompanying materials\r\n * are made available under the terms of the Eclipse Public License v1.0\r\n * which accompanies this distribution, and is available at\r\n * http\://www.eclipse.org/legal/epl-v10.html\r\n * \r\n * Contributors\:\r\n * Eike Stepper - initial API and implementation\r\n */</template><template autoinsert\="false" context\="typecomment_context" deleted\="false" description\="Comment for created types" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.typecomment" name\="typecomment">/**\r\n * @author Eike Stepper\r\n */</template><template autoinsert\="false" context\="fieldcomment_context" deleted\="false" description\="Comment for fields" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.fieldcomment" name\="fieldcomment"/><template autoinsert\="false" context\="methodcomment_context" deleted\="false" description\="Comment for non-overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodcomment" name\="methodcomment"/><template autoinsert\="false" context\="overridecomment_context" deleted\="false" description\="Comment for overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.overridecomment" name\="overridecomment"/><template autoinsert\="false" context\="delegatecomment_context" deleted\="false" description\="Comment for delegate methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.delegatecomment" name\="delegatecomment"/><template autoinsert\="true" context\="newtype_context" deleted\="false" description\="Newly created files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.newtype" name\="newtype">${filecomment}\r\n${package_declaration}\r\n\r\n${typecomment}\r\n${type_declaration}</template><template autoinsert\="true" context\="classbody_context" deleted\="false" description\="Code in new class type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.classbody" name\="classbody">\r\n</template><template autoinsert\="true" context\="interfacebody_context" deleted\="false" description\="Code in new interface type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.interfacebody" name\="interfacebody">\r\n</template><template autoinsert\="true" context\="enumbody_context" deleted\="false" description\="Code in new enum type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.enumbody" name\="enumbody">\r\n</template><template autoinsert\="true" context\="annotationbody_context" deleted\="false" description\="Code in new annotation type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.annotationbody" name\="annotationbody">\r\n</template><template autoinsert\="false" context\="catchblock_context" deleted\="false" description\="Code in new catch blocks" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.catchblock" name\="catchblock">${exception_var}.printStackTrace();</template><template autoinsert\="false" context\="methodbody_context" deleted\="false" description\="Code in created method stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodbody" name\="methodbody">${body_statement}</template><template autoinsert\="false" context\="constructorbody_context" deleted\="false" description\="Code in created constructor stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorbody" name\="constructorbody">${body_statement}</template><template autoinsert\="true" context\="getterbody_context" deleted\="false" description\="Code in created getters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.getterbody" name\="getterbody">return ${field};</template><template autoinsert\="true" context\="setterbody_context" deleted\="false" description\="Code in created setters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.setterbody" name\="setterbody">${field} \= ${param};</template></templates>
-sp_cleanup.add_default_serial_version_id=true
-sp_cleanup.add_generated_serial_version_id=false
-sp_cleanup.add_missing_annotations=true
-sp_cleanup.add_missing_deprecated_annotations=true
-sp_cleanup.add_missing_methods=false
-sp_cleanup.add_missing_nls_tags=false
-sp_cleanup.add_missing_override_annotations=true
-sp_cleanup.add_missing_override_annotations_interface_methods=false
-sp_cleanup.add_serial_version_id=false
-sp_cleanup.always_use_blocks=true
-sp_cleanup.always_use_parentheses_in_expressions=false
-sp_cleanup.always_use_this_for_non_static_field_access=false
-sp_cleanup.always_use_this_for_non_static_method_access=false
-sp_cleanup.convert_to_enhanced_for_loop=false
-sp_cleanup.correct_indentation=true
-sp_cleanup.format_source_code=true
-sp_cleanup.format_source_code_changes_only=false
-sp_cleanup.make_local_variable_final=false
-sp_cleanup.make_parameters_final=false
-sp_cleanup.make_private_fields_final=true
-sp_cleanup.make_type_abstract_if_missing_method=false
-sp_cleanup.make_variable_declarations_final=false
-sp_cleanup.never_use_blocks=false
-sp_cleanup.never_use_parentheses_in_expressions=true
-sp_cleanup.on_save_use_additional_actions=true
-sp_cleanup.organize_imports=true
-sp_cleanup.qualify_static_field_accesses_with_declaring_class=false
-sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
-sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
-sp_cleanup.qualify_static_member_accesses_with_declaring_class=false
-sp_cleanup.qualify_static_method_accesses_with_declaring_class=false
-sp_cleanup.remove_private_constructors=true
-sp_cleanup.remove_trailing_whitespaces=true
-sp_cleanup.remove_trailing_whitespaces_all=true
-sp_cleanup.remove_trailing_whitespaces_ignore_empty=false
-sp_cleanup.remove_unnecessary_casts=true
-sp_cleanup.remove_unnecessary_nls_tags=true
-sp_cleanup.remove_unused_imports=true
-sp_cleanup.remove_unused_local_variables=false
-sp_cleanup.remove_unused_private_fields=true
-sp_cleanup.remove_unused_private_members=false
-sp_cleanup.remove_unused_private_methods=true
-sp_cleanup.remove_unused_private_types=true
-sp_cleanup.sort_members=false
-sp_cleanup.sort_members_all=false
-sp_cleanup.use_blocks=true
-sp_cleanup.use_blocks_only_for_return_and_throw=false
-sp_cleanup.use_parentheses_in_expressions=true
-sp_cleanup.use_this_for_non_static_field_access=true
-sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true
-sp_cleanup.use_this_for_non_static_method_access=true
-sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true
+#Thu Feb 04 09:44:24 CET 2010
+cleanup.add_default_serial_version_id=true
+cleanup.add_generated_serial_version_id=false
+cleanup.add_missing_annotations=true
+cleanup.add_missing_deprecated_annotations=true
+cleanup.add_missing_methods=false
+cleanup.add_missing_nls_tags=false
+cleanup.add_missing_override_annotations=true
+cleanup.add_missing_override_annotations_interface_methods=true
+cleanup.add_serial_version_id=true
+cleanup.always_use_blocks=true
+cleanup.always_use_parentheses_in_expressions=false
+cleanup.always_use_this_for_non_static_field_access=false
+cleanup.always_use_this_for_non_static_method_access=false
+cleanup.convert_to_enhanced_for_loop=false
+cleanup.correct_indentation=true
+cleanup.format_source_code=true
+cleanup.format_source_code_changes_only=false
+cleanup.make_local_variable_final=true
+cleanup.make_parameters_final=false
+cleanup.make_private_fields_final=true
+cleanup.make_type_abstract_if_missing_method=false
+cleanup.make_variable_declarations_final=false
+cleanup.never_use_blocks=false
+cleanup.never_use_parentheses_in_expressions=true
+cleanup.organize_imports=true
+cleanup.qualify_static_field_accesses_with_declaring_class=false
+cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
+cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
+cleanup.qualify_static_member_accesses_with_declaring_class=false
+cleanup.qualify_static_method_accesses_with_declaring_class=false
+cleanup.remove_private_constructors=true
+cleanup.remove_trailing_whitespaces=true
+cleanup.remove_trailing_whitespaces_all=true
+cleanup.remove_trailing_whitespaces_ignore_empty=false
+cleanup.remove_unnecessary_casts=true
+cleanup.remove_unnecessary_nls_tags=true
+cleanup.remove_unused_imports=true
+cleanup.remove_unused_local_variables=false
+cleanup.remove_unused_private_fields=true
+cleanup.remove_unused_private_members=false
+cleanup.remove_unused_private_methods=true
+cleanup.remove_unused_private_types=true
+cleanup.sort_members=false
+cleanup.sort_members_all=false
+cleanup.use_blocks=true
+cleanup.use_blocks_only_for_return_and_throw=false
+cleanup.use_parentheses_in_expressions=true
+cleanup.use_this_for_non_static_field_access=true
+cleanup.use_this_for_non_static_field_access_only_if_necessary=true
+cleanup.use_this_for_non_static_method_access=true
+cleanup.use_this_for_non_static_method_access_only_if_necessary=true
+cleanup_profile=_EMFT
+cleanup_settings_version=2
+eclipse.preferences.version=1
+editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
+formatter_profile=_EMFT
+formatter_settings_version=11
+org.eclipse.jdt.ui.exception.name=ex
+org.eclipse.jdt.ui.gettersetter.use.is=true
+org.eclipse.jdt.ui.ignorelowercasenames=true
+org.eclipse.jdt.ui.importorder=org.eclipse.emf.cdo;org.eclipse.emf.internal.cdo;org.eclipse.net4j;org.eclipse.internal.net4j;org.eclipse.emf;org.eclipse;com;org;javax;java;
+org.eclipse.jdt.ui.javadoc=true
+org.eclipse.jdt.ui.keywordthis=false
+org.eclipse.jdt.ui.ondemandthreshold=99
+org.eclipse.jdt.ui.overrideannotation=true
+org.eclipse.jdt.ui.staticondemandthreshold=99
+org.eclipse.jdt.ui.text.custom_code_templates=<?xml version\="1.0" encoding\="UTF-8" standalone\="no"?><templates><template autoinsert\="false" context\="gettercomment_context" deleted\="false" description\="Comment for getter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.gettercomment" name\="gettercomment"/><template autoinsert\="false" context\="settercomment_context" deleted\="false" description\="Comment for setter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.settercomment" name\="settercomment"/><template autoinsert\="false" context\="constructorcomment_context" deleted\="false" description\="Comment for created constructors" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorcomment" name\="constructorcomment"/><template autoinsert\="false" context\="filecomment_context" deleted\="false" description\="Comment for created Java files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.filecomment" name\="filecomment">/*\r\n * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.\r\n * All rights reserved. This program and the accompanying materials\r\n * are made available under the terms of the Eclipse Public License v1.0\r\n * which accompanies this distribution, and is available at\r\n * http\://www.eclipse.org/legal/epl-v10.html\r\n * \r\n * Contributors\:\r\n * Eike Stepper - initial API and implementation\r\n */</template><template autoinsert\="false" context\="typecomment_context" deleted\="false" description\="Comment for created types" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.typecomment" name\="typecomment">/**\r\n * @author Eike Stepper\r\n */</template><template autoinsert\="false" context\="fieldcomment_context" deleted\="false" description\="Comment for fields" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.fieldcomment" name\="fieldcomment"/><template autoinsert\="false" context\="methodcomment_context" deleted\="false" description\="Comment for non-overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodcomment" name\="methodcomment"/><template autoinsert\="false" context\="overridecomment_context" deleted\="false" description\="Comment for overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.overridecomment" name\="overridecomment"/><template autoinsert\="false" context\="delegatecomment_context" deleted\="false" description\="Comment for delegate methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.delegatecomment" name\="delegatecomment"/><template autoinsert\="true" context\="newtype_context" deleted\="false" description\="Newly created files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.newtype" name\="newtype">${filecomment}\r\n${package_declaration}\r\n\r\n${typecomment}\r\n${type_declaration}</template><template autoinsert\="true" context\="classbody_context" deleted\="false" description\="Code in new class type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.classbody" name\="classbody">\r\n</template><template autoinsert\="true" context\="interfacebody_context" deleted\="false" description\="Code in new interface type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.interfacebody" name\="interfacebody">\r\n</template><template autoinsert\="true" context\="enumbody_context" deleted\="false" description\="Code in new enum type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.enumbody" name\="enumbody">\r\n</template><template autoinsert\="true" context\="annotationbody_context" deleted\="false" description\="Code in new annotation type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.annotationbody" name\="annotationbody">\r\n</template><template autoinsert\="false" context\="catchblock_context" deleted\="false" description\="Code in new catch blocks" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.catchblock" name\="catchblock">${exception_var}.printStackTrace();</template><template autoinsert\="false" context\="methodbody_context" deleted\="false" description\="Code in created method stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodbody" name\="methodbody">${body_statement}</template><template autoinsert\="false" context\="constructorbody_context" deleted\="false" description\="Code in created constructor stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorbody" name\="constructorbody">${body_statement}</template><template autoinsert\="true" context\="getterbody_context" deleted\="false" description\="Code in created getters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.getterbody" name\="getterbody">return ${field};</template><template autoinsert\="true" context\="setterbody_context" deleted\="false" description\="Code in created setters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.setterbody" name\="setterbody">${field} \= ${param};</template></templates>
+sp_cleanup.add_default_serial_version_id=true
+sp_cleanup.add_generated_serial_version_id=false
+sp_cleanup.add_missing_annotations=true
+sp_cleanup.add_missing_deprecated_annotations=true
+sp_cleanup.add_missing_methods=false
+sp_cleanup.add_missing_nls_tags=false
+sp_cleanup.add_missing_override_annotations=true
+sp_cleanup.add_missing_override_annotations_interface_methods=false
+sp_cleanup.add_serial_version_id=false
+sp_cleanup.always_use_blocks=true
+sp_cleanup.always_use_parentheses_in_expressions=false
+sp_cleanup.always_use_this_for_non_static_field_access=false
+sp_cleanup.always_use_this_for_non_static_method_access=false
+sp_cleanup.convert_to_enhanced_for_loop=false
+sp_cleanup.correct_indentation=true
+sp_cleanup.format_source_code=true
+sp_cleanup.format_source_code_changes_only=false
+sp_cleanup.make_local_variable_final=false
+sp_cleanup.make_parameters_final=false
+sp_cleanup.make_private_fields_final=true
+sp_cleanup.make_type_abstract_if_missing_method=false
+sp_cleanup.make_variable_declarations_final=false
+sp_cleanup.never_use_blocks=false
+sp_cleanup.never_use_parentheses_in_expressions=true
+sp_cleanup.on_save_use_additional_actions=true
+sp_cleanup.organize_imports=true
+sp_cleanup.qualify_static_field_accesses_with_declaring_class=false
+sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
+sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
+sp_cleanup.qualify_static_member_accesses_with_declaring_class=false
+sp_cleanup.qualify_static_method_accesses_with_declaring_class=false
+sp_cleanup.remove_private_constructors=true
+sp_cleanup.remove_trailing_whitespaces=true
+sp_cleanup.remove_trailing_whitespaces_all=true
+sp_cleanup.remove_trailing_whitespaces_ignore_empty=false
+sp_cleanup.remove_unnecessary_casts=true
+sp_cleanup.remove_unnecessary_nls_tags=true
+sp_cleanup.remove_unused_imports=true
+sp_cleanup.remove_unused_local_variables=false
+sp_cleanup.remove_unused_private_fields=true
+sp_cleanup.remove_unused_private_members=false
+sp_cleanup.remove_unused_private_methods=true
+sp_cleanup.remove_unused_private_types=true
+sp_cleanup.sort_members=false
+sp_cleanup.sort_members_all=false
+sp_cleanup.use_blocks=true
+sp_cleanup.use_blocks_only_for_return_and_throw=false
+sp_cleanup.use_parentheses_in_expressions=true
+sp_cleanup.use_this_for_non_static_field_access=true
+sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true
+sp_cleanup.use_this_for_non_static_method_access=true
+sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true
diff --git a/plugins/org.eclipse.net4j.tests/about.properties b/plugins/org.eclipse.net4j.tests/about.properties
index cd5cde2778..ef89222e2e 100644
--- a/plugins/org.eclipse.net4j.tests/about.properties
+++ b/plugins/org.eclipse.net4j.tests/about.properties
@@ -1,31 +1,31 @@
-# Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
-# All rights reserved. This program and the accompanying materials
-# are made available under the terms of the Eclipse Public License v1.0
-# which accompanies this distribution, and is available at
-# http://www.eclipse.org/legal/epl-v10.html
-#
-# Contributors:
-# Eike Stepper - initial API and implementation
-
-# NLS_MESSAGEFORMAT_VAR
-
-# ==============================================================================
-# Do not change the properties between this line and the last line containing:
-# %%% END OF TRANSLATED PROPERTIES %%%
-# Instead, either redefine an existing property, or create a new property,
-# append it to the end of the file, and change the code to use the new name.
-# ==============================================================================
-
-featureName = Net4j Signalling Platform Tests
-featureText = Net4j Signalling Platform Tests\n\
-Version: {featureVersion}\n\
-Build id: {0}\n\
-\n\
-Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others. All rights reserved.\n\
-\n\
-Visit http://wiki.eclipse.org/Net4j
-
-# ==============================================================================
-# %%% END OF TRANSLATED PROPERTIES %%%
-# The above properties have been shipped for translation.
-# ==============================================================================
+# Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Contributors:
+# Eike Stepper - initial API and implementation
+
+# NLS_MESSAGEFORMAT_VAR
+
+# ==============================================================================
+# Do not change the properties between this line and the last line containing:
+# %%% END OF TRANSLATED PROPERTIES %%%
+# Instead, either redefine an existing property, or create a new property,
+# append it to the end of the file, and change the code to use the new name.
+# ==============================================================================
+
+featureName = Net4j Signalling Platform Tests
+featureText = Net4j Signalling Platform Tests\n\
+Version: {featureVersion}\n\
+Build id: {0}\n\
+\n\
+Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others. All rights reserved.\n\
+\n\
+Visit http://wiki.eclipse.org/Net4j
+
+# ==============================================================================
+# %%% END OF TRANSLATED PROPERTIES %%%
+# The above properties have been shipped for translation.
+# ==============================================================================
diff --git a/plugins/org.eclipse.net4j.tests/build.properties b/plugins/org.eclipse.net4j.tests/build.properties
index e6c1dfd182..25caa95e46 100644
--- a/plugins/org.eclipse.net4j.tests/build.properties
+++ b/plugins/org.eclipse.net4j.tests/build.properties
@@ -1,29 +1,29 @@
-# Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
-# All rights reserved. This program and the accompanying materials
-# are made available under the terms of the Eclipse Public License v1.0
-# which accompanies this distribution, and is available at
-# http://www.eclipse.org/legal/epl-v10.html
-#
-# Contributors:
-# Eike Stepper - initial API and implementation
-
-# NLS_MESSAGEFORMAT_VAR
-
-source.. = src/
-output.. = bin/
-bin.includes = META-INF/,\
- .,\
- about.html,\
- copyright.txt,\
- plugin.properties,\
- test.xml,\
- about.ini,\
- about.mappings,\
- about.properties,\
- modeling32.png,\
- plugin.xml,\
- .options,\
- model/,\
- sslKey/
-src.includes = about.html,\
- copyright.txt
+# Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Contributors:
+# Eike Stepper - initial API and implementation
+
+# NLS_MESSAGEFORMAT_VAR
+
+source.. = src/
+output.. = bin/
+bin.includes = META-INF/,\
+ .,\
+ about.html,\
+ copyright.txt,\
+ plugin.properties,\
+ test.xml,\
+ about.ini,\
+ about.mappings,\
+ about.properties,\
+ modeling32.png,\
+ plugin.xml,\
+ .options,\
+ model/,\
+ sslKey/
+src.includes = about.html,\
+ copyright.txt
diff --git a/plugins/org.eclipse.net4j.tests/copyright.txt b/plugins/org.eclipse.net4j.tests/copyright.txt
index e921242cf0..8f6328980e 100644
--- a/plugins/org.eclipse.net4j.tests/copyright.txt
+++ b/plugins/org.eclipse.net4j.tests/copyright.txt
@@ -1,8 +1,8 @@
-Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
-All rights reserved. This program and the accompanying materials
-are made available under the terms of the Eclipse Public License v1.0
-which accompanies this distribution, and is available at
-http://www.eclipse.org/legal/epl-v10.html
-
-Contributors:
+Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+All rights reserved. This program and the accompanying materials
+are made available under the terms of the Eclipse Public License v1.0
+which accompanies this distribution, and is available at
+http://www.eclipse.org/legal/epl-v10.html
+
+Contributors:
Eike Stepper - initial API and implementation \ No newline at end of file
diff --git a/plugins/org.eclipse.net4j.tests/model/TestDef.genmodel b/plugins/org.eclipse.net4j.tests/model/TestDef.genmodel
index ce5481b001..dfe581686e 100644
--- a/plugins/org.eclipse.net4j.tests/model/TestDef.genmodel
+++ b/plugins/org.eclipse.net4j.tests/model/TestDef.genmodel
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<genmodel:GenModel xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"
- xmlns:genmodel="http://www.eclipse.org/emf/2002/GenModel" copyrightText=" * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.&#xA; * All rights reserved. This program and the accompanying materials&#xA; * are made available under the terms of the Eclipse Public License v1.0&#xA; * which accompanies this distribution, and is available at&#xA; * http://www.eclipse.org/legal/epl-v10.html&#xA;"
+ xmlns:genmodel="http://www.eclipse.org/emf/2002/GenModel"
modelDirectory="/org.eclipse.net4j.tests/src" editDirectory="" editorDirectory=""
modelPluginID="" modelName="TestDef" testsDirectory="" importerID="org.eclipse.emf.importer.ecore"
complianceLevel="5.0" copyrightFields="false" usedGenPackages="../../org.eclipse.net4j.util.defs/model/org.eclipse.net4j.util.defs.genmodel#//defs">
diff --git a/plugins/org.eclipse.net4j.tests/plugin.properties b/plugins/org.eclipse.net4j.tests/plugin.properties
index 549b22eb76..d1dca40f14 100644
--- a/plugins/org.eclipse.net4j.tests/plugin.properties
+++ b/plugins/org.eclipse.net4j.tests/plugin.properties
@@ -1,11 +1,11 @@
-# Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
-# All rights reserved. This program and the accompanying materials
-# are made available under the terms of the Eclipse Public License v1.0
-# which accompanies this distribution, and is available at
-# http://www.eclipse.org/legal/epl-v10.html
-#
-# Contributors:
-# Eike Stepper - initial API and implementation
-
-pluginName = Net4j Signalling Platform Tests
-providerName = Eclipse Modeling Project
+# Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+#
+# Contributors:
+# Eike Stepper - initial API and implementation
+
+pluginName = Net4j Signalling Platform Tests
+providerName = Eclipse Modeling Project
diff --git a/plugins/org.eclipse.net4j.tests/plugin.xml b/plugins/org.eclipse.net4j.tests/plugin.xml
index cd66d55bd1..e886a476db 100644
--- a/plugins/org.eclipse.net4j.tests/plugin.xml
+++ b/plugins/org.eclipse.net4j.tests/plugin.xml
@@ -1,24 +1,24 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<?eclipse version="3.4"?>
-<!--
- Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
- All rights reserved. This program and the accompanying materials
- are made available under the terms of the Eclipse Public License v1.0
- which accompanies this distribution, and is available at
- http://www.eclipse.org/legal/epl-v10.html
-
- Contributors:
- Eike Stepper - initial API and implementation
--->
-
-<plugin>
-
- <extension
- point="org.eclipse.net4j.util.factories">
- <factory
- class="org.eclipse.net4j.tests.signal.TestSignalProtocol$Factory"
- productGroup="org.eclipse.net4j.serverProtocols"
- type="signal.protocol"/>
- </extension>
-
-</plugin>
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<!--
+ Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ All rights reserved. This program and the accompanying materials
+ are made available under the terms of the Eclipse Public License v1.0
+ which accompanies this distribution, and is available at
+ http://www.eclipse.org/legal/epl-v10.html
+
+ Contributors:
+ Eike Stepper - initial API and implementation
+-->
+
+<plugin>
+
+ <extension
+ point="org.eclipse.net4j.util.factories">
+ <factory
+ class="org.eclipse.net4j.tests.signal.TestSignalProtocol$Factory"
+ productGroup="org.eclipse.net4j.serverProtocols"
+ type="signal.protocol"/>
+ </extension>
+
+</plugin>
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/AbstractProtocolTest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/AbstractProtocolTest.java
index a4603716be..5d523f69b3 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/AbstractProtocolTest.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/AbstractProtocolTest.java
@@ -1,32 +1,32 @@
-/*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- */
-package org.eclipse.net4j.tests;
-
-import org.eclipse.net4j.tests.signal.TestSignalProtocol;
-import org.eclipse.net4j.util.container.IManagedContainer;
-
-/**
- * @author Eike Stepper
- */
-public abstract class AbstractProtocolTest extends AbstractTransportTest
-{
- protected AbstractProtocolTest()
- {
- }
-
- @Override
- protected IManagedContainer createContainer()
- {
- IManagedContainer container = super.createContainer();
- container.registerFactory(new TestSignalProtocol.Factory());
- return container;
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.tests;
+
+import org.eclipse.net4j.tests.signal.TestSignalProtocol;
+import org.eclipse.net4j.util.container.IManagedContainer;
+
+/**
+ * @author Eike Stepper
+ */
+public abstract class AbstractProtocolTest extends AbstractTransportTest
+{
+ protected AbstractProtocolTest()
+ {
+ }
+
+ @Override
+ protected IManagedContainer createContainer()
+ {
+ IManagedContainer container = super.createContainer();
+ container.registerFactory(new TestSignalProtocol.Factory());
+ return container;
+ }
+}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/AbstractTransportTest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/AbstractTransportTest.java
index 69bc9785ed..f8706a6d42 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/AbstractTransportTest.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/AbstractTransportTest.java
@@ -1,204 +1,204 @@
-/*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- * Teerawat Chaiyakijpichet (No Magic Asia Ltd.) - SSL
- */
-package org.eclipse.net4j.tests;
-
-import org.eclipse.net4j.Net4jUtil;
-import org.eclipse.net4j.acceptor.IAcceptor;
-import org.eclipse.net4j.connector.IConnector;
-import org.eclipse.net4j.jvm.JVMUtil;
-import org.eclipse.net4j.tcp.TCPUtil;
-import org.eclipse.net4j.tcp.ssl.SSLUtil;
-import org.eclipse.net4j.util.container.ContainerUtil;
-import org.eclipse.net4j.util.container.IManagedContainer;
-import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
-import org.eclipse.net4j.util.tests.AbstractOMTest;
-
-/**
- * @author Eike Stepper
- * @author Teerawat Chaiyakijpichet (No Magic Asia Ltd.)
- */
-public abstract class AbstractTransportTest extends AbstractOMTest
-{
- protected static final String HOST = "localhost"; //$NON-NLS-1$
-
- protected IManagedContainer container;
-
- // SSL, the server and client need separate container in order to operate handshake.
- protected IManagedContainer separateContainer;
-
- private IAcceptor acceptor;
-
- private IConnector connector;
-
- protected AbstractTransportTest()
- {
- }
-
- @Override
- protected void doSetUp() throws Exception
- {
- super.doSetUp();
- // create container for JVM or TCP only.
- container = createContainer();
- LifecycleUtil.activate(container);
-
- if (!useJVMTransport() && useSSLTransport())
- {
- // the SSL need separate container between client and server
- separateContainer = createContainer();
- LifecycleUtil.activate(separateContainer);
- }
- }
-
- @Override
- protected void doTearDown() throws Exception
- {
- try
- {
- sleep(20);
- LifecycleUtil.deactivate(container);
- }
- finally
- {
- connector = null;
- acceptor = null;
- container = null;
- if (!useJVMTransport() && useSSLTransport())
- {
- separateContainer = null;
- }
- super.doTearDown();
- }
- }
-
- protected boolean useJVMTransport()
- {
- return false;
- }
-
- protected boolean useSSLTransport()
- {
- return false;
- }
-
- protected IManagedContainer createContainer()
- {
- IManagedContainer container = ContainerUtil.createContainer();
- Net4jUtil.prepareContainer(container);
- if (useJVMTransport())
- {
- JVMUtil.prepareContainer(container);
- }
- else
- {
- if (useSSLTransport())
- {
- SSLUtil.prepareContainer(container);
- }
- else
- {
- TCPUtil.prepareContainer(container);
- }
- }
-
- return container;
- }
-
- protected IAcceptor getAcceptor()
- {
- if (acceptor == null)
- {
- if (useJVMTransport())
- {
- acceptor = JVMUtil.getAcceptor(container, "default"); //$NON-NLS-1$
- }
- else
- {
- if (useSSLTransport())
- {
- acceptor = SSLUtil.getAcceptor(container, null);
- }
- else
- {
- acceptor = TCPUtil.getAcceptor(container, null);
- }
- }
- }
-
- return acceptor;
- }
-
- protected IConnector getConnector()
- {
- if (connector == null)
- {
- if (useJVMTransport())
- {
- connector = JVMUtil.getConnector(container, "default"); //$NON-NLS-1$
- }
- else
- {
- if (useSSLTransport())
- {
- // cannot use same container with the acceptor.
- connector = SSLUtil.getConnector(separateContainer, HOST);
- }
- else
- {
- connector = TCPUtil.getConnector(container, HOST);
- }
- }
- }
-
- return connector;
- }
-
- protected void startTransport() throws Exception
- {
- if (container != null)
- {
- IAcceptor acceptor = getAcceptor();
- LifecycleUtil.activate(acceptor);
-
- IConnector connector = getConnector();
- LifecycleUtil.activate(connector);
- }
- }
-
- protected void stopTransport() throws Exception
- {
- connector.close();
- connector = null;
-
- acceptor.close();
- acceptor = null;
- }
-
- protected void restartContainer() throws Exception
- {
- msg("RESTARTING CONTAINER"); //$NON-NLS-1$
- stopTransport();
-
- LifecycleUtil.deactivate(container);
- container = createContainer();
- LifecycleUtil.activate(container);
-
- if (!useJVMTransport() && useSSLTransport())
- {
- LifecycleUtil.deactivate(separateContainer);
- separateContainer = createContainer();
- LifecycleUtil.activate(separateContainer);
- }
- startTransport();
- msg("RESTARTING CONTAINER - FINISHED"); //$NON-NLS-1$
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ * Teerawat Chaiyakijpichet (No Magic Asia Ltd.) - SSL
+ */
+package org.eclipse.net4j.tests;
+
+import org.eclipse.net4j.Net4jUtil;
+import org.eclipse.net4j.acceptor.IAcceptor;
+import org.eclipse.net4j.connector.IConnector;
+import org.eclipse.net4j.jvm.JVMUtil;
+import org.eclipse.net4j.tcp.TCPUtil;
+import org.eclipse.net4j.tcp.ssl.SSLUtil;
+import org.eclipse.net4j.util.container.ContainerUtil;
+import org.eclipse.net4j.util.container.IManagedContainer;
+import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
+import org.eclipse.net4j.util.tests.AbstractOMTest;
+
+/**
+ * @author Eike Stepper
+ * @author Teerawat Chaiyakijpichet (No Magic Asia Ltd.)
+ */
+public abstract class AbstractTransportTest extends AbstractOMTest
+{
+ protected static final String HOST = "localhost"; //$NON-NLS-1$
+
+ protected IManagedContainer container;
+
+ // SSL, the server and client need separate container in order to operate handshake.
+ protected IManagedContainer separateContainer;
+
+ private IAcceptor acceptor;
+
+ private IConnector connector;
+
+ protected AbstractTransportTest()
+ {
+ }
+
+ @Override
+ protected void doSetUp() throws Exception
+ {
+ super.doSetUp();
+ // create container for JVM or TCP only.
+ container = createContainer();
+ LifecycleUtil.activate(container);
+
+ if (!useJVMTransport() && useSSLTransport())
+ {
+ // the SSL need separate container between client and server
+ separateContainer = createContainer();
+ LifecycleUtil.activate(separateContainer);
+ }
+ }
+
+ @Override
+ protected void doTearDown() throws Exception
+ {
+ try
+ {
+ sleep(20);
+ LifecycleUtil.deactivate(container);
+ }
+ finally
+ {
+ connector = null;
+ acceptor = null;
+ container = null;
+ if (!useJVMTransport() && useSSLTransport())
+ {
+ separateContainer = null;
+ }
+ super.doTearDown();
+ }
+ }
+
+ protected boolean useJVMTransport()
+ {
+ return false;
+ }
+
+ protected boolean useSSLTransport()
+ {
+ return false;
+ }
+
+ protected IManagedContainer createContainer()
+ {
+ IManagedContainer container = ContainerUtil.createContainer();
+ Net4jUtil.prepareContainer(container);
+ if (useJVMTransport())
+ {
+ JVMUtil.prepareContainer(container);
+ }
+ else
+ {
+ if (useSSLTransport())
+ {
+ SSLUtil.prepareContainer(container);
+ }
+ else
+ {
+ TCPUtil.prepareContainer(container);
+ }
+ }
+
+ return container;
+ }
+
+ protected IAcceptor getAcceptor()
+ {
+ if (acceptor == null)
+ {
+ if (useJVMTransport())
+ {
+ acceptor = JVMUtil.getAcceptor(container, "default"); //$NON-NLS-1$
+ }
+ else
+ {
+ if (useSSLTransport())
+ {
+ acceptor = SSLUtil.getAcceptor(container, null);
+ }
+ else
+ {
+ acceptor = TCPUtil.getAcceptor(container, null);
+ }
+ }
+ }
+
+ return acceptor;
+ }
+
+ protected IConnector getConnector()
+ {
+ if (connector == null)
+ {
+ if (useJVMTransport())
+ {
+ connector = JVMUtil.getConnector(container, "default"); //$NON-NLS-1$
+ }
+ else
+ {
+ if (useSSLTransport())
+ {
+ // cannot use same container with the acceptor.
+ connector = SSLUtil.getConnector(separateContainer, HOST);
+ }
+ else
+ {
+ connector = TCPUtil.getConnector(container, HOST);
+ }
+ }
+ }
+
+ return connector;
+ }
+
+ protected void startTransport() throws Exception
+ {
+ if (container != null)
+ {
+ IAcceptor acceptor = getAcceptor();
+ LifecycleUtil.activate(acceptor);
+
+ IConnector connector = getConnector();
+ LifecycleUtil.activate(connector);
+ }
+ }
+
+ protected void stopTransport() throws Exception
+ {
+ connector.close();
+ connector = null;
+
+ acceptor.close();
+ acceptor = null;
+ }
+
+ protected void restartContainer() throws Exception
+ {
+ msg("RESTARTING CONTAINER"); //$NON-NLS-1$
+ stopTransport();
+
+ LifecycleUtil.deactivate(container);
+ container = createContainer();
+ LifecycleUtil.activate(container);
+
+ if (!useJVMTransport() && useSSLTransport())
+ {
+ LifecycleUtil.deactivate(separateContainer);
+ separateContainer = createContainer();
+ LifecycleUtil.activate(separateContainer);
+ }
+ startTransport();
+ msg("RESTARTING CONTAINER - FINISHED"); //$NON-NLS-1$
+ }
+}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/AllSSLTests.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/AllSSLTests.java
index ee2aa2f5c8..d3629b3e8d 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/AllSSLTests.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/AllSSLTests.java
@@ -1,37 +1,37 @@
-/*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Teerawat Chaiyakijpichet (No Magic Asia Ltd.) - initial API and implementation
- */
-package org.eclipse.net4j.tests;
-
-import org.eclipse.net4j.tests.bugzilla.Bugzilla_241463_Test;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-/**
- * @author Teerawat Chaiyakijpichet (No Magic Asia Ltd.)
- */
-public class AllSSLTests
-{
- public static Test suite()
- {
- TestSuite suite = new TestSuite("Tests for SSL Net4j"); //$NON-NLS-1$
- suite.addTestSuite(ChannelTest.SSL.class);
- suite.addTestSuite(TCPConnectorTest.SSL.class);
- suite.addTestSuite(TransportTest.SSL.class);
- suite.addTestSuite(SignalTest.SSL.class);
- suite.addTestSuite(SignalMonitorTest.SSL.class);
- suite.addTestSuite(ExceptionTest.SSL.class);
- // Bugzillas
- suite.addTestSuite(Bugzilla_241463_Test.SSL.class);
-
- return suite;
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Teerawat Chaiyakijpichet (No Magic Asia Ltd.) - initial API and implementation
+ */
+package org.eclipse.net4j.tests;
+
+import org.eclipse.net4j.tests.bugzilla.Bugzilla_241463_Test;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * @author Teerawat Chaiyakijpichet (No Magic Asia Ltd.)
+ */
+public class AllSSLTests
+{
+ public static Test suite()
+ {
+ TestSuite suite = new TestSuite("Tests for SSL Net4j"); //$NON-NLS-1$
+ suite.addTestSuite(ChannelTest.SSL.class);
+ suite.addTestSuite(TCPConnectorTest.SSL.class);
+ suite.addTestSuite(TransportTest.SSL.class);
+ suite.addTestSuite(SignalTest.SSL.class);
+ suite.addTestSuite(SignalMonitorTest.SSL.class);
+ suite.addTestSuite(ExceptionTest.SSL.class);
+ // Bugzillas
+ suite.addTestSuite(Bugzilla_241463_Test.SSL.class);
+
+ return suite;
+ }
+}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/AllTests.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/AllTests.java
index 37e2ef8b85..cde0650580 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/AllTests.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/AllTests.java
@@ -1,77 +1,77 @@
-/*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- */
-package org.eclipse.net4j.tests;
-
-import org.eclipse.net4j.tests.bugzilla.Bugzilla_241463_Test;
-import org.eclipse.net4j.tests.bugzilla.Bugzilla_262875_Test;
-import org.eclipse.net4j.util.tests.ExpectedIOTest;
-import org.eclipse.net4j.util.tests.ExtendedIOTest;
-import org.eclipse.net4j.util.tests.MultiMapTest;
-import org.eclipse.net4j.util.tests.QueueWorkerWorkSerializerTest;
-import org.eclipse.net4j.util.tests.ReferenceValueMapTest;
-import org.eclipse.net4j.util.tests.SecurityTest;
-import org.eclipse.net4j.util.tests.SortedFileMapTest;
-import org.eclipse.net4j.util.tests.StringCompressorTest;
-import org.eclipse.net4j.util.tests.SynchronizingCorrelatorTest;
-import org.eclipse.net4j.util.tests.UUIDGeneratorTest;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-/**
- * @author Eike Stepper
- */
-public class AllTests
-{
- public static Test suite()
- {
- TestSuite suite = new TestSuite("Tests for Net4j"); //$NON-NLS-1$
- suite.addTestSuite(UUIDGeneratorTest.class);
- suite.addTestSuite(MultiMapTest.class);
- suite.addTestSuite(SortedFileMapTest.class);
- suite.addTestSuite(SynchronizingCorrelatorTest.class);
- suite.addTestSuite(ReferenceValueMapTest.class);
- suite.addTestSuite(BufferPoolTest.class);
- suite.addTestSuite(ExtendedIOTest.class);
- suite.addTestSuite(StringCompressorTest.class);
- suite.addTestSuite(ChannelTest.JVM.class);
- suite.addTestSuite(ChannelTest.TCP.class);
- // suite.addTestSuite(ChannelTest.SSL.class);
- suite.addTestSuite(TCPConnectorTest.TCP.class);
- // suite.addTestSuite(TCPConnectorTest.SSL.class);
- suite.addTestSuite(TransportTest.JVM.class);
- suite.addTestSuite(TransportTest.TCP.class);
- // suite.addTestSuite(TransportTest.SSL.class);
- suite.addTestSuite(SignalTest.TCP.class);
- // suite.addTestSuite(SignalTest.SSL.class);
- suite.addTestSuite(SignalMonitorTest.TCP.class);
- // suite.addTestSuite(SignalMonitorTest.SSL.class);
- suite.addTestSuite(ExceptionTest.TCP.class);
- // suite.addTestSuite(ExceptionTest.SSL.class);
- suite.addTestSuite(SecurityTest.class);
- suite.addTestSuite(QueueWorkerWorkSerializerTest.class);
- suite.addTestSuite(ExpectedIOTest.class);
-
- // Bugzillas
- suite.addTestSuite(Bugzilla_241463_Test.TCP.class);
- // suite.addTestSuite(Bugzilla_241463_Test.SSL.class);
- suite.addTestSuite(Bugzilla_262875_Test.class);
-
- // Defs
- // suite.addTestSuite(TestDefTest.class);
- // suite.addTestSuite(TCPAcceptorDefImplTest.class);
- // suite.addTestSuite(TCPConnectorDefImplTest.class);
- // suite.addTestSuite(JVMAcceptorDefImplTest.class);
- // suite.addTestSuite(JVMConnectorDefImplTest.class);
-
- return suite;
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.tests;
+
+import org.eclipse.net4j.tests.bugzilla.Bugzilla_241463_Test;
+import org.eclipse.net4j.tests.bugzilla.Bugzilla_262875_Test;
+import org.eclipse.net4j.util.tests.ExpectedIOTest;
+import org.eclipse.net4j.util.tests.ExtendedIOTest;
+import org.eclipse.net4j.util.tests.MultiMapTest;
+import org.eclipse.net4j.util.tests.QueueWorkerWorkSerializerTest;
+import org.eclipse.net4j.util.tests.ReferenceValueMapTest;
+import org.eclipse.net4j.util.tests.SecurityTest;
+import org.eclipse.net4j.util.tests.SortedFileMapTest;
+import org.eclipse.net4j.util.tests.StringCompressorTest;
+import org.eclipse.net4j.util.tests.SynchronizingCorrelatorTest;
+import org.eclipse.net4j.util.tests.UUIDGeneratorTest;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * @author Eike Stepper
+ */
+public class AllTests
+{
+ public static Test suite()
+ {
+ TestSuite suite = new TestSuite("Tests for Net4j"); //$NON-NLS-1$
+ suite.addTestSuite(UUIDGeneratorTest.class);
+ suite.addTestSuite(MultiMapTest.class);
+ suite.addTestSuite(SortedFileMapTest.class);
+ suite.addTestSuite(SynchronizingCorrelatorTest.class);
+ suite.addTestSuite(ReferenceValueMapTest.class);
+ suite.addTestSuite(BufferPoolTest.class);
+ suite.addTestSuite(ExtendedIOTest.class);
+ suite.addTestSuite(StringCompressorTest.class);
+ suite.addTestSuite(ChannelTest.JVM.class);
+ suite.addTestSuite(ChannelTest.TCP.class);
+ // suite.addTestSuite(ChannelTest.SSL.class);
+ suite.addTestSuite(TCPConnectorTest.TCP.class);
+ // suite.addTestSuite(TCPConnectorTest.SSL.class);
+ suite.addTestSuite(TransportTest.JVM.class);
+ suite.addTestSuite(TransportTest.TCP.class);
+ // suite.addTestSuite(TransportTest.SSL.class);
+ suite.addTestSuite(SignalTest.TCP.class);
+ // suite.addTestSuite(SignalTest.SSL.class);
+ suite.addTestSuite(SignalMonitorTest.TCP.class);
+ // suite.addTestSuite(SignalMonitorTest.SSL.class);
+ suite.addTestSuite(ExceptionTest.TCP.class);
+ // suite.addTestSuite(ExceptionTest.SSL.class);
+ suite.addTestSuite(SecurityTest.class);
+ suite.addTestSuite(QueueWorkerWorkSerializerTest.class);
+ suite.addTestSuite(ExpectedIOTest.class);
+
+ // Bugzillas
+ suite.addTestSuite(Bugzilla_241463_Test.TCP.class);
+ // suite.addTestSuite(Bugzilla_241463_Test.SSL.class);
+ suite.addTestSuite(Bugzilla_262875_Test.class);
+
+ // Defs
+ // suite.addTestSuite(TestDefTest.class);
+ // suite.addTestSuite(TCPAcceptorDefImplTest.class);
+ // suite.addTestSuite(TCPConnectorDefImplTest.class);
+ // suite.addTestSuite(JVMAcceptorDefImplTest.class);
+ // suite.addTestSuite(JVMConnectorDefImplTest.class);
+
+ return suite;
+ }
+}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/BufferPoolTest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/BufferPoolTest.java
index fbf695d95c..6090e3b784 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/BufferPoolTest.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/BufferPoolTest.java
@@ -1,97 +1,97 @@
-/*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- */
-package org.eclipse.net4j.tests;
-
-import org.eclipse.net4j.Net4jUtil;
-import org.eclipse.net4j.buffer.IBuffer;
-import org.eclipse.net4j.buffer.IBufferPool;
-import org.eclipse.net4j.util.ReflectUtil;
-import org.eclipse.net4j.util.io.IOUtil;
-import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
-import org.eclipse.net4j.util.tests.AbstractOMTest;
-
-import java.util.ArrayList;
-import java.util.Collection;
-
-/**
- * @author Eike Stepper
- */
-public class BufferPoolTest extends AbstractOMTest
-{
- private static IBufferPool bufferPool = Net4jUtil.createBufferPool();
-
- private static Collection<byte[]> memory = new ArrayList<byte[]>();
-
- @Override
- protected void doTearDown() throws Exception
- {
- memory.clear();
- super.doTearDown();
- }
-
- public void testBufferPool() throws Exception
- {
- LifecycleUtil.activate(bufferPool);
-
- IBuffer[] buffers = new IBuffer[10];
- for (int i = 0; i < buffers.length; i++)
- {
- buffers[i] = bufferPool.provideBuffer();
- }
-
- for (int i = 0; i < buffers.length; i++)
- {
- bufferPool.retainBuffer(buffers[i]);
- buffers[i] = null;
- }
-
- while (Net4jUtil.getPooledBuffers(bufferPool) > 0 && allocate())
- {
- sleep(100);
- ReflectUtil.dump(bufferPool);
- }
-
- LifecycleUtil.deactivate(bufferPool);
- }
-
- private static void msg()
- {
- msg("pooledBuffers = " + Net4jUtil.getPooledBuffers(bufferPool)); //$NON-NLS-1$
- }
-
- private static boolean allocate()
- {
- try
- {
- IOUtil.OUT().println("allocating from " + Runtime.getRuntime().freeMemory()); //$NON-NLS-1$
- for (int i = 0; i < 10; i++)
- {
- memory.add(new byte[1000000]);
- }
-
- msg();
- return true;
- }
- catch (Throwable t)
- {
- return false;
- }
- }
-
- @SuppressWarnings("unused")
- private static void gc()
- {
- msg();
- IOUtil.OUT().println("collecting garbage"); //$NON-NLS-1$
- System.gc();
- msg();
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.tests;
+
+import org.eclipse.net4j.Net4jUtil;
+import org.eclipse.net4j.buffer.IBuffer;
+import org.eclipse.net4j.buffer.IBufferPool;
+import org.eclipse.net4j.util.ReflectUtil;
+import org.eclipse.net4j.util.io.IOUtil;
+import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
+import org.eclipse.net4j.util.tests.AbstractOMTest;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+/**
+ * @author Eike Stepper
+ */
+public class BufferPoolTest extends AbstractOMTest
+{
+ private static IBufferPool bufferPool = Net4jUtil.createBufferPool();
+
+ private static Collection<byte[]> memory = new ArrayList<byte[]>();
+
+ @Override
+ protected void doTearDown() throws Exception
+ {
+ memory.clear();
+ super.doTearDown();
+ }
+
+ public void testBufferPool() throws Exception
+ {
+ LifecycleUtil.activate(bufferPool);
+
+ IBuffer[] buffers = new IBuffer[10];
+ for (int i = 0; i < buffers.length; i++)
+ {
+ buffers[i] = bufferPool.provideBuffer();
+ }
+
+ for (int i = 0; i < buffers.length; i++)
+ {
+ bufferPool.retainBuffer(buffers[i]);
+ buffers[i] = null;
+ }
+
+ while (Net4jUtil.getPooledBuffers(bufferPool) > 0 && allocate())
+ {
+ sleep(100);
+ ReflectUtil.dump(bufferPool);
+ }
+
+ LifecycleUtil.deactivate(bufferPool);
+ }
+
+ private static void msg()
+ {
+ msg("pooledBuffers = " + Net4jUtil.getPooledBuffers(bufferPool)); //$NON-NLS-1$
+ }
+
+ private static boolean allocate()
+ {
+ try
+ {
+ IOUtil.OUT().println("allocating from " + Runtime.getRuntime().freeMemory()); //$NON-NLS-1$
+ for (int i = 0; i < 10; i++)
+ {
+ memory.add(new byte[1000000]);
+ }
+
+ msg();
+ return true;
+ }
+ catch (Throwable t)
+ {
+ return false;
+ }
+ }
+
+ @SuppressWarnings("unused")
+ private static void gc()
+ {
+ msg();
+ IOUtil.OUT().println("collecting garbage"); //$NON-NLS-1$
+ System.gc();
+ msg();
+ }
+}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/ChannelTest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/ChannelTest.java
index b8a8cb158b..29f6ed8f14 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/ChannelTest.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/ChannelTest.java
@@ -1,371 +1,371 @@
-/*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- * Teerawat Chaiyakijpichet (No Magic Asia Ltd.) - SSL
- */
-package org.eclipse.net4j.tests;
-
-import org.eclipse.net4j.channel.IChannel;
-import org.eclipse.net4j.tests.data.TinyData;
-import org.eclipse.net4j.tests.signal.ArrayRequest;
-import org.eclipse.net4j.tests.signal.TestSignalProtocol;
-import org.eclipse.net4j.util.concurrent.ConcurrencyUtil;
-import org.eclipse.net4j.util.concurrent.MonitoredThread;
-import org.eclipse.net4j.util.concurrent.MonitoredThread.MultiThreadMonitor;
-import org.eclipse.net4j.util.io.IOUtil;
-import org.eclipse.net4j.util.lifecycle.ILifecycle;
-import org.eclipse.net4j.util.lifecycle.LifecycleEventAdapter;
-
-import org.eclipse.spi.net4j.InternalConnector;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-/**
- * @author Eike Stepper
- */
-public abstract class ChannelTest extends AbstractProtocolTest
-{
- private static final long TIMEOUT = 20000;
-
- private static final int THREADS = 40;
-
- private List<TestSignalProtocol> protocols;
-
- public ChannelTest()
- {
- }
-
- public void testSingleThreadNoData() throws Exception
- {
- final LatchTimeOuter timeOuter = new LatchTimeOuter(4);
- final DeactivationListener deactivationListener = new DeactivationListener()
- {
- @Override
- protected void onDeactivated(ILifecycle lifecycle)
- {
- super.onDeactivated(lifecycle);
- timeOuter.countDown();
- }
- };
-
- TestSignalProtocol protocol = openTestSignalProtocol();
- protocol.addListener(deactivationListener);
- assertActive(protocol);
-
- IChannel channel = protocol.getChannel();
- channel.addListener(deactivationListener);
- assertActive(channel);
-
- InternalConnector serverConnector = (InternalConnector)getAcceptor().getAcceptedConnectors()[0];
- Collection<IChannel> serverChannels = serverConnector.getChannels();
- assertEquals(1, serverChannels.size());
-
- IChannel serverChannel = serverChannels.iterator().next();
- serverChannel.addListener(deactivationListener);
- assertActive(serverChannel);
-
- TestSignalProtocol serverProtocol = (TestSignalProtocol)serverChannel.getReceiveHandler();
- serverProtocol.addListener(deactivationListener);
- assertActive(serverProtocol);
-
- protocol.close();
- assertInactive(protocol);
- assertInactive(channel);
-
- assertInactive(serverChannel);
- assertInactive(serverProtocol);
- assertEquals(0, serverConnector.getChannels().size());
-
- timeOuter.assertNoTimeOut();
- Set<ILifecycle> deactivatedSet = deactivationListener.getDeactivatedSet();
- assertEquals(true, deactivatedSet.contains(channel));
- assertEquals(true, deactivatedSet.contains(protocol));
- assertEquals(true, deactivatedSet.contains(serverChannel));
- assertEquals(true, deactivatedSet.contains(serverProtocol));
-
- synchronized (protocols)
- {
- assertEquals(0, protocols.size());
- }
- }
-
- public void testSingleThreadNoData100() throws Exception
- {
- disableConsole();
- for (int i = 0; i < 100; i++)
- {
- IOUtil.OUT().println(Thread.currentThread().getName() + ": " + i); //$NON-NLS-1$
- testSingleThreadNoData();
- }
- }
-
- public void testSingleThreadTinyData() throws Exception
- {
- TestSignalProtocol protocol = openTestSignalProtocol();
- assertActive(protocol);
-
- byte[] data = TinyData.getBytes();
- byte[] result = new ArrayRequest(protocol, data).send();
- assertEquals(true, Arrays.equals(data, result));
-
- protocol.close();
- assertInactive(protocol);
- }
-
- public void testSingleThreadTinyData100() throws Exception
- {
- disableConsole();
- for (int i = 0; i < 100; i++)
- {
- IOUtil.OUT().println(Thread.currentThread().getName() + ": " + i); //$NON-NLS-1$
- testSingleThreadTinyData();
- }
- }
-
- public void testMultiThreadNoData() throws Exception
- {
- MultiThreadMonitor threadMonitor = new MultiThreadMonitor(TIMEOUT);
- for (int i = 0; i < THREADS; i++)
- {
- threadMonitor.addThread(new MonitoredThread("TEST-THREAD-" + i, threadMonitor) //$NON-NLS-1$
- {
- @Override
- protected void doRun() throws Exception
- {
- for (int i = 0; i < 100; i++)
- {
- IOUtil.OUT().println(Thread.currentThread().getName() + ": " + i); //$NON-NLS-1$
- TestSignalProtocol protocol = openTestSignalProtocol();
- assertActive(protocol);
-
- protocol.close();
- assertInactive(protocol);
- heartBeat();
- }
- }
- });
- }
-
- disableConsole();
- threadMonitor.run();
- enableConsole();
- }
-
- public void testMultiThreadTinyData() throws Exception
- {
- MultiThreadMonitor threadMonitor = new MultiThreadMonitor(TIMEOUT);
-
- for (int i = 0; i < THREADS; i++)
- {
- threadMonitor.addThread(new MonitoredThread("TEST-THREAD-" + i, threadMonitor) //$NON-NLS-1$
- {
- @Override
- protected void doRun() throws Exception
- {
- for (int i = 0; i < 100; i++)
- {
- IOUtil.OUT().println(Thread.currentThread().getName() + ": " + i); //$NON-NLS-1$
- TestSignalProtocol protocol = openTestSignalProtocol();
- assertActive(protocol);
- heartBeat();
-
- byte[] data = TinyData.getBytes();
- byte[] result = new ArrayRequest(protocol, data).send();
- assertEquals(true, Arrays.equals(data, result));
- heartBeat();
-
- protocol.close();
- assertInactive(protocol);
- heartBeat();
- }
- }
- });
- }
-
- disableConsole();
- threadMonitor.run();
- enableConsole();
- }
-
- public void testMultiThreadDataLoop() throws Exception
- {
- MultiThreadMonitor threadMonitor = new MultiThreadMonitor(TIMEOUT, 10L);
- for (int i = 0; i < THREADS; i++)
- {
- threadMonitor.addThread(new MonitoredThread("TEST-THREAD-" + i, threadMonitor) //$NON-NLS-1$
- {
- @Override
- protected void doRun() throws Exception
- {
- for (int i = 0; i < 10; i++)
- {
- long start = System.currentTimeMillis();
- TestSignalProtocol protocol = openTestSignalProtocol();
- assertActive(protocol);
-
- for (int j = 0; j < 50; j++)
- {
- byte[] data = TinyData.getBytes();
- byte[] result = new ArrayRequest(protocol, data).send();
- assertEquals(true, Arrays.equals(data, result));
-
- heartBeat();
- ConcurrencyUtil.sleep(10L);
- }
-
- protocol.close();
- assertInactive(protocol);
- long stop = System.currentTimeMillis();
- IOUtil.OUT().println(Thread.currentThread().getName() + ": " + i + " (" + (stop - start) + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
- }
- });
- }
-
- disableConsole();
- threadMonitor.run();
- enableConsole();
- }
-
- @Override
- protected abstract boolean useJVMTransport();
-
- @Override
- protected void doSetUp() throws Exception
- {
- super.doSetUp();
- startTransport();
- getConnector().setOpenChannelTimeout(TIMEOUT);
- protocols = new ArrayList<TestSignalProtocol>();
- }
-
- @Override
- protected void doTearDown() throws Exception
- {
- for (TestSignalProtocol protocol : protocols)
- {
- protocol.close();
- }
-
- protocols = null;
-
- getConnector().close();
- super.doTearDown();
- }
-
- private TestSignalProtocol openTestSignalProtocol()
- {
- final TestSignalProtocol protocol = new TestSignalProtocol(getConnector());
- synchronized (protocols)
- {
- protocols.add(protocol);
- protocol.getChannel().addListener(new LifecycleEventAdapter()
- {
- @Override
- protected void onDeactivated(ILifecycle lifecycle)
- {
- synchronized (protocols)
- {
- protocol.getChannel().removeListener(this);
- boolean removed = protocols.remove(protocol);
- assertEquals(true, removed);
- }
- }
- });
- }
-
- return protocol;
- }
-
- /**
- * @author Eike Stepper
- */
- private static class DeactivationListener extends LifecycleEventAdapter
- {
- private Set<ILifecycle> deactivatedSet = new HashSet<ILifecycle>();
-
- public DeactivationListener()
- {
- }
-
- public Set<ILifecycle> getDeactivatedSet()
- {
- return deactivatedSet;
- }
-
- @Override
- protected void onDeactivated(ILifecycle lifecycle)
- {
- synchronized (deactivatedSet)
- {
- deactivatedSet.add(lifecycle);
- deactivatedSet.notifyAll();
- }
- }
- }
-
- /**
- * @author Eike Stepper
- */
- public static final class TCP extends ChannelTest
- {
- @Override
- protected boolean useJVMTransport()
- {
- return false;
- }
-
- @Override
- protected boolean useSSLTransport()
- {
- return false;
- }
- }
-
- /**
- * @author Eike Stepper
- */
- public static final class JVM extends ChannelTest
- {
- @Override
- protected boolean useJVMTransport()
- {
- return true;
- }
-
- @Override
- protected boolean useSSLTransport()
- {
- return false;
- }
- }
-
- /**
- * @author Teerawat Chaiyakijpichet (No Magic Asia Ltd.)
- */
- public static final class SSL extends ChannelTest
- {
- @Override
- protected boolean useJVMTransport()
- {
- return false;
- }
-
- @Override
- protected boolean useSSLTransport()
- {
- return true;
- }
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ * Teerawat Chaiyakijpichet (No Magic Asia Ltd.) - SSL
+ */
+package org.eclipse.net4j.tests;
+
+import org.eclipse.net4j.channel.IChannel;
+import org.eclipse.net4j.tests.data.TinyData;
+import org.eclipse.net4j.tests.signal.ArrayRequest;
+import org.eclipse.net4j.tests.signal.TestSignalProtocol;
+import org.eclipse.net4j.util.concurrent.ConcurrencyUtil;
+import org.eclipse.net4j.util.concurrent.MonitoredThread;
+import org.eclipse.net4j.util.concurrent.MonitoredThread.MultiThreadMonitor;
+import org.eclipse.net4j.util.io.IOUtil;
+import org.eclipse.net4j.util.lifecycle.ILifecycle;
+import org.eclipse.net4j.util.lifecycle.LifecycleEventAdapter;
+
+import org.eclipse.spi.net4j.InternalConnector;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+/**
+ * @author Eike Stepper
+ */
+public abstract class ChannelTest extends AbstractProtocolTest
+{
+ private static final long TIMEOUT = 20000;
+
+ private static final int THREADS = 40;
+
+ private List<TestSignalProtocol> protocols;
+
+ public ChannelTest()
+ {
+ }
+
+ public void testSingleThreadNoData() throws Exception
+ {
+ final LatchTimeOuter timeOuter = new LatchTimeOuter(4);
+ final DeactivationListener deactivationListener = new DeactivationListener()
+ {
+ @Override
+ protected void onDeactivated(ILifecycle lifecycle)
+ {
+ super.onDeactivated(lifecycle);
+ timeOuter.countDown();
+ }
+ };
+
+ TestSignalProtocol protocol = openTestSignalProtocol();
+ protocol.addListener(deactivationListener);
+ assertActive(protocol);
+
+ IChannel channel = protocol.getChannel();
+ channel.addListener(deactivationListener);
+ assertActive(channel);
+
+ InternalConnector serverConnector = (InternalConnector)getAcceptor().getAcceptedConnectors()[0];
+ Collection<IChannel> serverChannels = serverConnector.getChannels();
+ assertEquals(1, serverChannels.size());
+
+ IChannel serverChannel = serverChannels.iterator().next();
+ serverChannel.addListener(deactivationListener);
+ assertActive(serverChannel);
+
+ TestSignalProtocol serverProtocol = (TestSignalProtocol)serverChannel.getReceiveHandler();
+ serverProtocol.addListener(deactivationListener);
+ assertActive(serverProtocol);
+
+ protocol.close();
+ assertInactive(protocol);
+ assertInactive(channel);
+
+ assertInactive(serverChannel);
+ assertInactive(serverProtocol);
+ assertEquals(0, serverConnector.getChannels().size());
+
+ timeOuter.assertNoTimeOut();
+ Set<ILifecycle> deactivatedSet = deactivationListener.getDeactivatedSet();
+ assertEquals(true, deactivatedSet.contains(channel));
+ assertEquals(true, deactivatedSet.contains(protocol));
+ assertEquals(true, deactivatedSet.contains(serverChannel));
+ assertEquals(true, deactivatedSet.contains(serverProtocol));
+
+ synchronized (protocols)
+ {
+ assertEquals(0, protocols.size());
+ }
+ }
+
+ public void testSingleThreadNoData100() throws Exception
+ {
+ disableConsole();
+ for (int i = 0; i < 100; i++)
+ {
+ IOUtil.OUT().println(Thread.currentThread().getName() + ": " + i); //$NON-NLS-1$
+ testSingleThreadNoData();
+ }
+ }
+
+ public void testSingleThreadTinyData() throws Exception
+ {
+ TestSignalProtocol protocol = openTestSignalProtocol();
+ assertActive(protocol);
+
+ byte[] data = TinyData.getBytes();
+ byte[] result = new ArrayRequest(protocol, data).send();
+ assertEquals(true, Arrays.equals(data, result));
+
+ protocol.close();
+ assertInactive(protocol);
+ }
+
+ public void testSingleThreadTinyData100() throws Exception
+ {
+ disableConsole();
+ for (int i = 0; i < 100; i++)
+ {
+ IOUtil.OUT().println(Thread.currentThread().getName() + ": " + i); //$NON-NLS-1$
+ testSingleThreadTinyData();
+ }
+ }
+
+ public void testMultiThreadNoData() throws Exception
+ {
+ MultiThreadMonitor threadMonitor = new MultiThreadMonitor(TIMEOUT);
+ for (int i = 0; i < THREADS; i++)
+ {
+ threadMonitor.addThread(new MonitoredThread("TEST-THREAD-" + i, threadMonitor) //$NON-NLS-1$
+ {
+ @Override
+ protected void doRun() throws Exception
+ {
+ for (int i = 0; i < 100; i++)
+ {
+ IOUtil.OUT().println(Thread.currentThread().getName() + ": " + i); //$NON-NLS-1$
+ TestSignalProtocol protocol = openTestSignalProtocol();
+ assertActive(protocol);
+
+ protocol.close();
+ assertInactive(protocol);
+ heartBeat();
+ }
+ }
+ });
+ }
+
+ disableConsole();
+ threadMonitor.run();
+ enableConsole();
+ }
+
+ public void testMultiThreadTinyData() throws Exception
+ {
+ MultiThreadMonitor threadMonitor = new MultiThreadMonitor(TIMEOUT);
+
+ for (int i = 0; i < THREADS; i++)
+ {
+ threadMonitor.addThread(new MonitoredThread("TEST-THREAD-" + i, threadMonitor) //$NON-NLS-1$
+ {
+ @Override
+ protected void doRun() throws Exception
+ {
+ for (int i = 0; i < 100; i++)
+ {
+ IOUtil.OUT().println(Thread.currentThread().getName() + ": " + i); //$NON-NLS-1$
+ TestSignalProtocol protocol = openTestSignalProtocol();
+ assertActive(protocol);
+ heartBeat();
+
+ byte[] data = TinyData.getBytes();
+ byte[] result = new ArrayRequest(protocol, data).send();
+ assertEquals(true, Arrays.equals(data, result));
+ heartBeat();
+
+ protocol.close();
+ assertInactive(protocol);
+ heartBeat();
+ }
+ }
+ });
+ }
+
+ disableConsole();
+ threadMonitor.run();
+ enableConsole();
+ }
+
+ public void testMultiThreadDataLoop() throws Exception
+ {
+ MultiThreadMonitor threadMonitor = new MultiThreadMonitor(TIMEOUT, 10L);
+ for (int i = 0; i < THREADS; i++)
+ {
+ threadMonitor.addThread(new MonitoredThread("TEST-THREAD-" + i, threadMonitor) //$NON-NLS-1$
+ {
+ @Override
+ protected void doRun() throws Exception
+ {
+ for (int i = 0; i < 10; i++)
+ {
+ long start = System.currentTimeMillis();
+ TestSignalProtocol protocol = openTestSignalProtocol();
+ assertActive(protocol);
+
+ for (int j = 0; j < 50; j++)
+ {
+ byte[] data = TinyData.getBytes();
+ byte[] result = new ArrayRequest(protocol, data).send();
+ assertEquals(true, Arrays.equals(data, result));
+
+ heartBeat();
+ ConcurrencyUtil.sleep(10L);
+ }
+
+ protocol.close();
+ assertInactive(protocol);
+ long stop = System.currentTimeMillis();
+ IOUtil.OUT().println(Thread.currentThread().getName() + ": " + i + " (" + (stop - start) + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+ }
+ });
+ }
+
+ disableConsole();
+ threadMonitor.run();
+ enableConsole();
+ }
+
+ @Override
+ protected abstract boolean useJVMTransport();
+
+ @Override
+ protected void doSetUp() throws Exception
+ {
+ super.doSetUp();
+ startTransport();
+ getConnector().setOpenChannelTimeout(TIMEOUT);
+ protocols = new ArrayList<TestSignalProtocol>();
+ }
+
+ @Override
+ protected void doTearDown() throws Exception
+ {
+ for (TestSignalProtocol protocol : protocols)
+ {
+ protocol.close();
+ }
+
+ protocols = null;
+
+ getConnector().close();
+ super.doTearDown();
+ }
+
+ private TestSignalProtocol openTestSignalProtocol()
+ {
+ final TestSignalProtocol protocol = new TestSignalProtocol(getConnector());
+ synchronized (protocols)
+ {
+ protocols.add(protocol);
+ protocol.getChannel().addListener(new LifecycleEventAdapter()
+ {
+ @Override
+ protected void onDeactivated(ILifecycle lifecycle)
+ {
+ synchronized (protocols)
+ {
+ protocol.getChannel().removeListener(this);
+ boolean removed = protocols.remove(protocol);
+ assertEquals(true, removed);
+ }
+ }
+ });
+ }
+
+ return protocol;
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ private static class DeactivationListener extends LifecycleEventAdapter
+ {
+ private Set<ILifecycle> deactivatedSet = new HashSet<ILifecycle>();
+
+ public DeactivationListener()
+ {
+ }
+
+ public Set<ILifecycle> getDeactivatedSet()
+ {
+ return deactivatedSet;
+ }
+
+ @Override
+ protected void onDeactivated(ILifecycle lifecycle)
+ {
+ synchronized (deactivatedSet)
+ {
+ deactivatedSet.add(lifecycle);
+ deactivatedSet.notifyAll();
+ }
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static final class TCP extends ChannelTest
+ {
+ @Override
+ protected boolean useJVMTransport()
+ {
+ return false;
+ }
+
+ @Override
+ protected boolean useSSLTransport()
+ {
+ return false;
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static final class JVM extends ChannelTest
+ {
+ @Override
+ protected boolean useJVMTransport()
+ {
+ return true;
+ }
+
+ @Override
+ protected boolean useSSLTransport()
+ {
+ return false;
+ }
+ }
+
+ /**
+ * @author Teerawat Chaiyakijpichet (No Magic Asia Ltd.)
+ */
+ public static final class SSL extends ChannelTest
+ {
+ @Override
+ protected boolean useJVMTransport()
+ {
+ return false;
+ }
+
+ @Override
+ protected boolean useSSLTransport()
+ {
+ return true;
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/ExceptionTest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/ExceptionTest.java
index 46417a24b4..11f64315a5 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/ExceptionTest.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/ExceptionTest.java
@@ -1,167 +1,167 @@
-/*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- * Teerawat Chaiyakijpichet (No Magic Asia Ltd.) - SSL
- */
-package org.eclipse.net4j.tests;
-
-import org.eclipse.net4j.signal.RemoteException;
-import org.eclipse.net4j.tests.signal.ExceptionRequest;
-import org.eclipse.net4j.tests.signal.TestSignalProtocol;
-import org.eclipse.net4j.util.io.IOUtil;
-
-import java.io.IOException;
-import java.rmi.AlreadyBoundException;
-
-/**
- * @author Eike Stepper
- */
-public class ExceptionTest extends AbstractProtocolTest
-{
- public ExceptionTest()
- {
- }
-
- public void testExceptionInIRequesting() throws Exception
- {
- exceptionInPhase(1, false);
- }
-
- public void testExceptionInIndicating() throws Exception
- {
- exceptionInPhase(2, false);
- }
-
- public void testExceptionInResponding() throws Exception
- {
- exceptionInPhase(3, false);
- }
-
- public void testExceptionInConfirming() throws Exception
- {
- exceptionInPhase(4, false);
- }
-
- public void testIOExceptionInIRequesting() throws Exception
- {
- exceptionInPhase(1, true);
- }
-
- public void testIOExceptionInIndicating() throws Exception
- {
- exceptionInPhase(2, true);
- }
-
- public void testIOExceptionInResponding() throws Exception
- {
- exceptionInPhase(3, true);
- }
-
- public void testIOExceptionInConfirming() throws Exception
- {
- exceptionInPhase(4, true);
- }
-
- private void exceptionInPhase(int phase, boolean ioProblem) throws Exception
- {
- startTransport();
- TestSignalProtocol protocol = new TestSignalProtocol(getConnector());
-
- try
- {
- new ExceptionRequest(protocol, phase, ioProblem).send();
- fail("Exception expected"); //$NON-NLS-1$
- }
- catch (Exception ex)
- {
- IOUtil.print(ex);
- if (ioProblem)
- {
- IOException ioe = null;
- if (phase == 2 || phase == 3)
- {
- if (ex instanceof RemoteException)
- {
- assertEquals(((RemoteException)ex).whileResponding(), phase == 3);
- ioe = (IOException)ex.getCause();
- }
- else
- {
- fail("RemoteException expected"); //$NON-NLS-1$
- }
- }
- else
- {
- ioe = (IOException)ex;
- }
-
- assertEquals(TestSignalProtocol.SIMULATED_EXCEPTION, ioe.getMessage());
- }
- else
- {
- ClassNotFoundException cnfe = null;
- if (phase == 2 || phase == 3)
- {
- if (ex instanceof RemoteException)
- {
- assertEquals(((RemoteException)ex).whileResponding(), phase == 3);
- cnfe = (ClassNotFoundException)ex.getCause();
- }
- else
- {
- fail("RemoteException expected"); //$NON-NLS-1$
- }
- }
- else
- {
- cnfe = (ClassNotFoundException)ex;
- }
-
- AlreadyBoundException abe = (AlreadyBoundException)cnfe.getCause();
- assertEquals(TestSignalProtocol.SIMULATED_EXCEPTION, abe.getMessage());
- }
- }
- }
-
- /**
- * @author Eike Stepper
- */
- public static final class TCP extends ExceptionTest
- {
- @Override
- protected boolean useJVMTransport()
- {
- return false;
- }
-
- @Override
- protected boolean useSSLTransport()
- {
- return false;
- }
- }
-
- /**
- * @author Teerawat Chaiyakijpichet (No Magic Asia Ltd.)
- */
- public static final class SSL extends ExceptionTest
- {
- @Override
- protected boolean useJVMTransport()
- {
- return false;
- }
-
- @Override
- protected boolean useSSLTransport()
- {
- return true;
- }
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ * Teerawat Chaiyakijpichet (No Magic Asia Ltd.) - SSL
+ */
+package org.eclipse.net4j.tests;
+
+import org.eclipse.net4j.signal.RemoteException;
+import org.eclipse.net4j.tests.signal.ExceptionRequest;
+import org.eclipse.net4j.tests.signal.TestSignalProtocol;
+import org.eclipse.net4j.util.io.IOUtil;
+
+import java.io.IOException;
+import java.rmi.AlreadyBoundException;
+
+/**
+ * @author Eike Stepper
+ */
+public class ExceptionTest extends AbstractProtocolTest
+{
+ public ExceptionTest()
+ {
+ }
+
+ public void testExceptionInIRequesting() throws Exception
+ {
+ exceptionInPhase(1, false);
+ }
+
+ public void testExceptionInIndicating() throws Exception
+ {
+ exceptionInPhase(2, false);
+ }
+
+ public void testExceptionInResponding() throws Exception
+ {
+ exceptionInPhase(3, false);
+ }
+
+ public void testExceptionInConfirming() throws Exception
+ {
+ exceptionInPhase(4, false);
+ }
+
+ public void testIOExceptionInIRequesting() throws Exception
+ {
+ exceptionInPhase(1, true);
+ }
+
+ public void testIOExceptionInIndicating() throws Exception
+ {
+ exceptionInPhase(2, true);
+ }
+
+ public void testIOExceptionInResponding() throws Exception
+ {
+ exceptionInPhase(3, true);
+ }
+
+ public void testIOExceptionInConfirming() throws Exception
+ {
+ exceptionInPhase(4, true);
+ }
+
+ private void exceptionInPhase(int phase, boolean ioProblem) throws Exception
+ {
+ startTransport();
+ TestSignalProtocol protocol = new TestSignalProtocol(getConnector());
+
+ try
+ {
+ new ExceptionRequest(protocol, phase, ioProblem).send();
+ fail("Exception expected"); //$NON-NLS-1$
+ }
+ catch (Exception ex)
+ {
+ IOUtil.print(ex);
+ if (ioProblem)
+ {
+ IOException ioe = null;
+ if (phase == 2 || phase == 3)
+ {
+ if (ex instanceof RemoteException)
+ {
+ assertEquals(((RemoteException)ex).whileResponding(), phase == 3);
+ ioe = (IOException)ex.getCause();
+ }
+ else
+ {
+ fail("RemoteException expected"); //$NON-NLS-1$
+ }
+ }
+ else
+ {
+ ioe = (IOException)ex;
+ }
+
+ assertEquals(TestSignalProtocol.SIMULATED_EXCEPTION, ioe.getMessage());
+ }
+ else
+ {
+ ClassNotFoundException cnfe = null;
+ if (phase == 2 || phase == 3)
+ {
+ if (ex instanceof RemoteException)
+ {
+ assertEquals(((RemoteException)ex).whileResponding(), phase == 3);
+ cnfe = (ClassNotFoundException)ex.getCause();
+ }
+ else
+ {
+ fail("RemoteException expected"); //$NON-NLS-1$
+ }
+ }
+ else
+ {
+ cnfe = (ClassNotFoundException)ex;
+ }
+
+ AlreadyBoundException abe = (AlreadyBoundException)cnfe.getCause();
+ assertEquals(TestSignalProtocol.SIMULATED_EXCEPTION, abe.getMessage());
+ }
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static final class TCP extends ExceptionTest
+ {
+ @Override
+ protected boolean useJVMTransport()
+ {
+ return false;
+ }
+
+ @Override
+ protected boolean useSSLTransport()
+ {
+ return false;
+ }
+ }
+
+ /**
+ * @author Teerawat Chaiyakijpichet (No Magic Asia Ltd.)
+ */
+ public static final class SSL extends ExceptionTest
+ {
+ @Override
+ protected boolean useJVMTransport()
+ {
+ return false;
+ }
+
+ @Override
+ protected boolean useSSLTransport()
+ {
+ return true;
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/SelectorTest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/SelectorTest.java
index 236651bd63..bed8237abb 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/SelectorTest.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/SelectorTest.java
@@ -1,37 +1,37 @@
-/*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- */
-package org.eclipse.net4j.tests;
-
-import java.nio.channels.Selector;
-import java.nio.channels.spi.SelectorProvider;
-
-import junit.framework.TestCase;
-
-/**
- * @author Eike Stepper
- */
-public class SelectorTest extends TestCase
-{
- public void testOpen() throws Exception
- {
- SelectorProvider provider = SelectorProvider.provider();
- System.out.println(provider.getClass().getName());
- for (int i = 0; i < 5; i++)
- {
- long start = System.currentTimeMillis();
- Selector selector = provider.openSelector();
- long duration = System.currentTimeMillis() - start;
-
- System.out.println(duration);
- selector.close();
- }
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.tests;
+
+import java.nio.channels.Selector;
+import java.nio.channels.spi.SelectorProvider;
+
+import junit.framework.TestCase;
+
+/**
+ * @author Eike Stepper
+ */
+public class SelectorTest extends TestCase
+{
+ public void testOpen() throws Exception
+ {
+ SelectorProvider provider = SelectorProvider.provider();
+ System.out.println(provider.getClass().getName());
+ for (int i = 0; i < 5; i++)
+ {
+ long start = System.currentTimeMillis();
+ Selector selector = provider.openSelector();
+ long duration = System.currentTimeMillis() - start;
+
+ System.out.println(duration);
+ selector.close();
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/SignalMonitorTest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/SignalMonitorTest.java
index 839f57cb8e..5d5440b096 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/SignalMonitorTest.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/SignalMonitorTest.java
@@ -1,218 +1,218 @@
-/*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- * Teerawat Chaiyakijpichet (No Magic Asia Ltd.) - SSL
- */
-package org.eclipse.net4j.tests;
-
-import org.eclipse.net4j.signal.IndicationWithMonitoring;
-import org.eclipse.net4j.signal.RequestWithMonitoring;
-import org.eclipse.net4j.signal.SignalProtocol;
-import org.eclipse.net4j.signal.SignalReactor;
-import org.eclipse.net4j.util.container.IManagedContainer;
-import org.eclipse.net4j.util.factory.ProductCreationException;
-import org.eclipse.net4j.util.io.ExtendedDataInputStream;
-import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
-import org.eclipse.net4j.util.om.monitor.Monitor;
-import org.eclipse.net4j.util.om.monitor.OMMonitor;
-
-import org.eclipse.spi.net4j.ServerProtocolFactory;
-
-/**
- * @author Eike Stepper
- */
-public class SignalMonitorTest extends AbstractTransportTest
-{
- public static final String PROTOCOL_TYPE = "protocol"; //$NON-NLS-1$
-
- public static final short SIGNAL_ID = 1;
-
- @Override
- protected IManagedContainer createContainer()
- {
- IManagedContainer container = super.createContainer();
- container.registerFactory(new ServerProtocolFactory(PROTOCOL_TYPE)
- {
- public Object create(String description) throws ProductCreationException
- {
- return new SignalProtocol<Object>(PROTOCOL_TYPE)
- {
- @Override
- protected SignalReactor createSignalReactor(short signalID)
- {
- switch (signalID)
- {
- case SIGNAL_ID:
- return new IndicationWithMonitoring(this, SIGNAL_ID)
- {
- @Override
- protected void indicating(ExtendedDataInputStream in, OMMonitor monitor) throws Exception
- {
- monitor.begin(1 + 100);
-
- try
- {
- in.readBoolean();
- monitor.worked();
-
- for (int i = 0; i < 100; i++)
- {
- sleep(100);
- monitor.worked();
- }
- }
- finally
- {
- monitor.done();
- }
- }
-
- @Override
- protected void responding(ExtendedDataOutputStream out, OMMonitor monitor) throws Exception
- {
- monitor.begin();
-
- try
- {
- out.writeBoolean(true);
- monitor.worked();
- }
- finally
- {
- monitor.done();
- }
- }
- };
-
- default:
- return super.createSignalReactor(signalID);
- }
- }
- };
- }
- });
-
- return container;
- }
-
- public void testMonitorProgress() throws Exception
- {
- startTransport();
- SignalProtocol<Object> protocol = new ClientProtocol();
- protocol.open(getConnector());
-
- RequestWithMonitoring<Boolean> request = new RequestWithMonitoring<Boolean>(protocol, SIGNAL_ID)
- {
- @Override
- protected void requesting(ExtendedDataOutputStream out, OMMonitor monitor) throws Exception
- {
- monitor.begin();
-
- try
- {
- out.writeBoolean(true);
- monitor.worked();
- }
- finally
- {
- monitor.done();
- }
- }
-
- @Override
- protected Boolean confirming(ExtendedDataInputStream in, OMMonitor monitor) throws Exception
- {
- monitor.begin();
-
- try
- {
- boolean result = in.readBoolean();
- monitor.worked();
- return result;
- }
- finally
- {
- monitor.done();
- }
- }
- };
-
- request.send(4000L, new TestMonitor());
- sleep(200);
- protocol.close();
- }
-
- /**
- * @author Eike Stepper
- */
- public static final class ClientProtocol extends SignalProtocol<Object>
- {
- public ClientProtocol()
- {
- super(PROTOCOL_TYPE);
- }
- }
-
- /**
- * @author Eike Stepper
- */
- private static final class TestMonitor extends Monitor
- {
- @Override
- public OMMonitor begin(double totalWork)
- {
- super.begin(totalWork);
- System.out.println("totalWork: " + getTotalWork()); //$NON-NLS-1$
- return this;
- }
-
- @Override
- public void worked(double work)
- {
- super.worked(work);
- System.out.println("work: " + getWork()); //$NON-NLS-1$
- }
- }
-
- /**
- * @author Eike Stepper
- */
- public static final class TCP extends SignalMonitorTest
- {
- @Override
- protected boolean useJVMTransport()
- {
- return false;
- }
-
- @Override
- protected boolean useSSLTransport()
- {
- return false;
- }
- }
-
- /**
- * @author Teerawat Chaiyakijpichet (No Magic Asia Ltd.)
- */
- public static final class SSL extends SignalMonitorTest
- {
- @Override
- protected boolean useJVMTransport()
- {
- return false;
- }
-
- @Override
- protected boolean useSSLTransport()
- {
- return true;
- }
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ * Teerawat Chaiyakijpichet (No Magic Asia Ltd.) - SSL
+ */
+package org.eclipse.net4j.tests;
+
+import org.eclipse.net4j.signal.IndicationWithMonitoring;
+import org.eclipse.net4j.signal.RequestWithMonitoring;
+import org.eclipse.net4j.signal.SignalProtocol;
+import org.eclipse.net4j.signal.SignalReactor;
+import org.eclipse.net4j.util.container.IManagedContainer;
+import org.eclipse.net4j.util.factory.ProductCreationException;
+import org.eclipse.net4j.util.io.ExtendedDataInputStream;
+import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
+import org.eclipse.net4j.util.om.monitor.Monitor;
+import org.eclipse.net4j.util.om.monitor.OMMonitor;
+
+import org.eclipse.spi.net4j.ServerProtocolFactory;
+
+/**
+ * @author Eike Stepper
+ */
+public class SignalMonitorTest extends AbstractTransportTest
+{
+ public static final String PROTOCOL_TYPE = "protocol"; //$NON-NLS-1$
+
+ public static final short SIGNAL_ID = 1;
+
+ @Override
+ protected IManagedContainer createContainer()
+ {
+ IManagedContainer container = super.createContainer();
+ container.registerFactory(new ServerProtocolFactory(PROTOCOL_TYPE)
+ {
+ public Object create(String description) throws ProductCreationException
+ {
+ return new SignalProtocol<Object>(PROTOCOL_TYPE)
+ {
+ @Override
+ protected SignalReactor createSignalReactor(short signalID)
+ {
+ switch (signalID)
+ {
+ case SIGNAL_ID:
+ return new IndicationWithMonitoring(this, SIGNAL_ID)
+ {
+ @Override
+ protected void indicating(ExtendedDataInputStream in, OMMonitor monitor) throws Exception
+ {
+ monitor.begin(1 + 100);
+
+ try
+ {
+ in.readBoolean();
+ monitor.worked();
+
+ for (int i = 0; i < 100; i++)
+ {
+ sleep(100);
+ monitor.worked();
+ }
+ }
+ finally
+ {
+ monitor.done();
+ }
+ }
+
+ @Override
+ protected void responding(ExtendedDataOutputStream out, OMMonitor monitor) throws Exception
+ {
+ monitor.begin();
+
+ try
+ {
+ out.writeBoolean(true);
+ monitor.worked();
+ }
+ finally
+ {
+ monitor.done();
+ }
+ }
+ };
+
+ default:
+ return super.createSignalReactor(signalID);
+ }
+ }
+ };
+ }
+ });
+
+ return container;
+ }
+
+ public void testMonitorProgress() throws Exception
+ {
+ startTransport();
+ SignalProtocol<Object> protocol = new ClientProtocol();
+ protocol.open(getConnector());
+
+ RequestWithMonitoring<Boolean> request = new RequestWithMonitoring<Boolean>(protocol, SIGNAL_ID)
+ {
+ @Override
+ protected void requesting(ExtendedDataOutputStream out, OMMonitor monitor) throws Exception
+ {
+ monitor.begin();
+
+ try
+ {
+ out.writeBoolean(true);
+ monitor.worked();
+ }
+ finally
+ {
+ monitor.done();
+ }
+ }
+
+ @Override
+ protected Boolean confirming(ExtendedDataInputStream in, OMMonitor monitor) throws Exception
+ {
+ monitor.begin();
+
+ try
+ {
+ boolean result = in.readBoolean();
+ monitor.worked();
+ return result;
+ }
+ finally
+ {
+ monitor.done();
+ }
+ }
+ };
+
+ request.send(4000L, new TestMonitor());
+ sleep(200);
+ protocol.close();
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static final class ClientProtocol extends SignalProtocol<Object>
+ {
+ public ClientProtocol()
+ {
+ super(PROTOCOL_TYPE);
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ private static final class TestMonitor extends Monitor
+ {
+ @Override
+ public OMMonitor begin(double totalWork)
+ {
+ super.begin(totalWork);
+ System.out.println("totalWork: " + getTotalWork()); //$NON-NLS-1$
+ return this;
+ }
+
+ @Override
+ public void worked(double work)
+ {
+ super.worked(work);
+ System.out.println("work: " + getWork()); //$NON-NLS-1$
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static final class TCP extends SignalMonitorTest
+ {
+ @Override
+ protected boolean useJVMTransport()
+ {
+ return false;
+ }
+
+ @Override
+ protected boolean useSSLTransport()
+ {
+ return false;
+ }
+ }
+
+ /**
+ * @author Teerawat Chaiyakijpichet (No Magic Asia Ltd.)
+ */
+ public static final class SSL extends SignalMonitorTest
+ {
+ @Override
+ protected boolean useJVMTransport()
+ {
+ return false;
+ }
+
+ @Override
+ protected boolean useSSLTransport()
+ {
+ return true;
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/SignalStreamWrappingTest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/SignalStreamWrappingTest.java
index e19236c3ee..90a7788f58 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/SignalStreamWrappingTest.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/SignalStreamWrappingTest.java
@@ -1,88 +1,88 @@
-/*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- */
-package org.eclipse.net4j.tests;
-
-import org.eclipse.net4j.signal.wrapping.XORStreamWrapperInjector;
-import org.eclipse.net4j.tests.data.HugeData;
-import org.eclipse.net4j.tests.data.TinyData;
-import org.eclipse.net4j.tests.signal.ArrayRequest;
-import org.eclipse.net4j.tests.signal.TestSignalProtocol;
-import org.eclipse.net4j.util.container.IManagedContainer;
-import org.eclipse.net4j.util.io.XORStreamWrapper;
-
-import java.util.Arrays;
-
-/**
- * @author Eike Stepper
- */
-public class SignalStreamWrappingTest extends AbstractProtocolTest
-{
- private static final int[] KEY = { 1, 2, 3, 4, 5 };
-
- @Override
- protected IManagedContainer createContainer()
- {
- IManagedContainer container = super.createContainer();
- container.addPostProcessor(new XORStreamWrapperInjector(TestSignalProtocol.PROTOCOL_NAME, KEY));
- return container;
- }
-
- public void testXORStreamWrapping() throws Exception
- {
- TestSignalProtocol protocol = null;
-
- try
- {
- startTransport();
- protocol = new TestSignalProtocol(getConnector());
- protocol.setStreamWrapper(new XORStreamWrapper(KEY));
- protocol.setTimeout(1000000L);
-
- byte[] data = HugeData.getBytes();
- byte[] result = new ArrayRequest(protocol, data).send();
- assertEquals(true, Arrays.equals(data, result));
- }
- finally
- {
- if (protocol != null)
- {
- protocol.close();
- }
- }
- }
-
- public void testXORStreamWrappingWithMultipleSignals() throws Exception
- {
- TestSignalProtocol protocol = null;
-
- try
- {
- startTransport();
- protocol = new TestSignalProtocol(getConnector());
- protocol.setStreamWrapper(new XORStreamWrapper(KEY));
- protocol.setTimeout(1000000L);
-
- for (int i = 0; i < 20; i++)
- {
- byte[] data = TinyData.getBytes();
- byte[] result = new ArrayRequest(protocol, data).send();
- assertEquals(true, Arrays.equals(data, result));
- }
- }
- finally
- {
- if (protocol != null)
- {
- protocol.close();
- }
- }
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.tests;
+
+import org.eclipse.net4j.signal.wrapping.XORStreamWrapperInjector;
+import org.eclipse.net4j.tests.data.HugeData;
+import org.eclipse.net4j.tests.data.TinyData;
+import org.eclipse.net4j.tests.signal.ArrayRequest;
+import org.eclipse.net4j.tests.signal.TestSignalProtocol;
+import org.eclipse.net4j.util.container.IManagedContainer;
+import org.eclipse.net4j.util.io.XORStreamWrapper;
+
+import java.util.Arrays;
+
+/**
+ * @author Eike Stepper
+ */
+public class SignalStreamWrappingTest extends AbstractProtocolTest
+{
+ private static final int[] KEY = { 1, 2, 3, 4, 5 };
+
+ @Override
+ protected IManagedContainer createContainer()
+ {
+ IManagedContainer container = super.createContainer();
+ container.addPostProcessor(new XORStreamWrapperInjector(TestSignalProtocol.PROTOCOL_NAME, KEY));
+ return container;
+ }
+
+ public void testXORStreamWrapping() throws Exception
+ {
+ TestSignalProtocol protocol = null;
+
+ try
+ {
+ startTransport();
+ protocol = new TestSignalProtocol(getConnector());
+ protocol.setStreamWrapper(new XORStreamWrapper(KEY));
+ protocol.setTimeout(1000000L);
+
+ byte[] data = HugeData.getBytes();
+ byte[] result = new ArrayRequest(protocol, data).send();
+ assertEquals(true, Arrays.equals(data, result));
+ }
+ finally
+ {
+ if (protocol != null)
+ {
+ protocol.close();
+ }
+ }
+ }
+
+ public void testXORStreamWrappingWithMultipleSignals() throws Exception
+ {
+ TestSignalProtocol protocol = null;
+
+ try
+ {
+ startTransport();
+ protocol = new TestSignalProtocol(getConnector());
+ protocol.setStreamWrapper(new XORStreamWrapper(KEY));
+ protocol.setTimeout(1000000L);
+
+ for (int i = 0; i < 20; i++)
+ {
+ byte[] data = TinyData.getBytes();
+ byte[] result = new ArrayRequest(protocol, data).send();
+ assertEquals(true, Arrays.equals(data, result));
+ }
+ }
+ finally
+ {
+ if (protocol != null)
+ {
+ protocol.close();
+ }
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/SignalTest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/SignalTest.java
index 680787ef5e..263c619df7 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/SignalTest.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/SignalTest.java
@@ -1,175 +1,175 @@
-/*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- * Teerawat Chaiyakijpichet (No Magic Asia Ltd.) - SSL
- */
-package org.eclipse.net4j.tests;
-
-import org.eclipse.net4j.internal.tcp.TCPConnector;
-import org.eclipse.net4j.tests.data.TinyData;
-import org.eclipse.net4j.tests.signal.ArrayRequest;
-import org.eclipse.net4j.tests.signal.AsyncRequest;
-import org.eclipse.net4j.tests.signal.IntRequest;
-import org.eclipse.net4j.tests.signal.StringRequest;
-import org.eclipse.net4j.tests.signal.TestSignalProtocol;
-import org.eclipse.net4j.util.ReflectUtil;
-import org.eclipse.net4j.util.lifecycle.ILifecycle;
-import org.eclipse.net4j.util.om.OMPlatform;
-
-import java.io.IOException;
-import java.lang.reflect.Field;
-import java.nio.channels.SocketChannel;
-import java.util.Arrays;
-
-/**
- * @author Eike Stepper
- */
-public class SignalTest extends AbstractProtocolTest
-{
- public void testInteger() throws Exception
- {
- TestSignalProtocol protocol = null;
-
- try
- {
- startTransport();
- protocol = new TestSignalProtocol(getConnector());
- int data = 0x0a;
- int result = new IntRequest(protocol, data).send();
- assertEquals(data, result);
- }
- finally
- {
- if (protocol != null)
- {
- protocol.close();
- }
- }
- }
-
- public void testArray() throws Exception
- {
- TestSignalProtocol protocol = null;
-
- try
- {
- startTransport();
- protocol = new TestSignalProtocol(getConnector());
- byte[] data = TinyData.getBytes();
- byte[] result = new ArrayRequest(protocol, data).send();
- assertEquals(true, Arrays.equals(data, result));
- }
- finally
- {
- if (protocol != null)
- {
- protocol.close();
- }
- }
- }
-
- public void testAsync() throws Exception
- {
- TestSignalProtocol protocol = null;
-
- try
- {
- startTransport();
- OMPlatform.INSTANCE.setDebugging(false);
- protocol = new TestSignalProtocol(getConnector());
- String data = TinyData.getText();
- for (int i = 0; i < 1000; i++)
- {
- msg("Loop " + i); //$NON-NLS-1$
- new AsyncRequest(protocol, data).sendAsync();
- String result = new StringRequest(protocol, data).send();
- assertEquals(data, result);
- }
- }
- finally
- {
- if (protocol != null)
- {
- protocol.close();
- }
- }
- }
-
- public void testCloseSocketChannel() throws Exception
- {
- TestSignalProtocol protocol = null;
-
- try
- {
- startTransport();
- protocol = new TestSignalProtocol(getConnector());
- final ILifecycle lifecycle = protocol;
-
- closeSocketChannel((TCPConnector)getAcceptor().getAcceptedConnectors()[0]);
- new PollingTimeOuter()
- {
- @Override
- protected boolean successful()
- {
- return !lifecycle.isActive();
- }
- }.assertNoTimeOut();
- }
- finally
- {
- if (protocol != null)
- {
- protocol.close();
- }
- }
- }
-
- private static void closeSocketChannel(TCPConnector connector) throws IOException
- {
- Field field = ReflectUtil.getField(TCPConnector.class, "socketChannel");
- SocketChannel socketChannel = (SocketChannel)ReflectUtil.getValue(field, connector);
- socketChannel.close();
- }
-
- /**
- * @author Eike Stepper
- */
- public static final class TCP extends SignalTest
- {
- @Override
- protected boolean useJVMTransport()
- {
- return false;
- }
-
- @Override
- protected boolean useSSLTransport()
- {
- return false;
- }
- }
-
- /**
- * @author Teerawat Chaiyakijpichet (No Magic Asia Ltd.)
- */
- public static final class SSL extends SignalTest
- {
- @Override
- protected boolean useJVMTransport()
- {
- return false;
- }
-
- @Override
- protected boolean useSSLTransport()
- {
- return true;
- }
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ * Teerawat Chaiyakijpichet (No Magic Asia Ltd.) - SSL
+ */
+package org.eclipse.net4j.tests;
+
+import org.eclipse.net4j.internal.tcp.TCPConnector;
+import org.eclipse.net4j.tests.data.TinyData;
+import org.eclipse.net4j.tests.signal.ArrayRequest;
+import org.eclipse.net4j.tests.signal.AsyncRequest;
+import org.eclipse.net4j.tests.signal.IntRequest;
+import org.eclipse.net4j.tests.signal.StringRequest;
+import org.eclipse.net4j.tests.signal.TestSignalProtocol;
+import org.eclipse.net4j.util.ReflectUtil;
+import org.eclipse.net4j.util.lifecycle.ILifecycle;
+import org.eclipse.net4j.util.om.OMPlatform;
+
+import java.io.IOException;
+import java.lang.reflect.Field;
+import java.nio.channels.SocketChannel;
+import java.util.Arrays;
+
+/**
+ * @author Eike Stepper
+ */
+public class SignalTest extends AbstractProtocolTest
+{
+ public void testInteger() throws Exception
+ {
+ TestSignalProtocol protocol = null;
+
+ try
+ {
+ startTransport();
+ protocol = new TestSignalProtocol(getConnector());
+ int data = 0x0a;
+ int result = new IntRequest(protocol, data).send();
+ assertEquals(data, result);
+ }
+ finally
+ {
+ if (protocol != null)
+ {
+ protocol.close();
+ }
+ }
+ }
+
+ public void testArray() throws Exception
+ {
+ TestSignalProtocol protocol = null;
+
+ try
+ {
+ startTransport();
+ protocol = new TestSignalProtocol(getConnector());
+ byte[] data = TinyData.getBytes();
+ byte[] result = new ArrayRequest(protocol, data).send();
+ assertEquals(true, Arrays.equals(data, result));
+ }
+ finally
+ {
+ if (protocol != null)
+ {
+ protocol.close();
+ }
+ }
+ }
+
+ public void testAsync() throws Exception
+ {
+ TestSignalProtocol protocol = null;
+
+ try
+ {
+ startTransport();
+ OMPlatform.INSTANCE.setDebugging(false);
+ protocol = new TestSignalProtocol(getConnector());
+ String data = TinyData.getText();
+ for (int i = 0; i < 1000; i++)
+ {
+ msg("Loop " + i); //$NON-NLS-1$
+ new AsyncRequest(protocol, data).sendAsync();
+ String result = new StringRequest(protocol, data).send();
+ assertEquals(data, result);
+ }
+ }
+ finally
+ {
+ if (protocol != null)
+ {
+ protocol.close();
+ }
+ }
+ }
+
+ public void testCloseSocketChannel() throws Exception
+ {
+ TestSignalProtocol protocol = null;
+
+ try
+ {
+ startTransport();
+ protocol = new TestSignalProtocol(getConnector());
+ final ILifecycle lifecycle = protocol;
+
+ closeSocketChannel((TCPConnector)getAcceptor().getAcceptedConnectors()[0]);
+ new PollingTimeOuter()
+ {
+ @Override
+ protected boolean successful()
+ {
+ return !lifecycle.isActive();
+ }
+ }.assertNoTimeOut();
+ }
+ finally
+ {
+ if (protocol != null)
+ {
+ protocol.close();
+ }
+ }
+ }
+
+ private static void closeSocketChannel(TCPConnector connector) throws IOException
+ {
+ Field field = ReflectUtil.getField(TCPConnector.class, "socketChannel");
+ SocketChannel socketChannel = (SocketChannel)ReflectUtil.getValue(field, connector);
+ socketChannel.close();
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static final class TCP extends SignalTest
+ {
+ @Override
+ protected boolean useJVMTransport()
+ {
+ return false;
+ }
+
+ @Override
+ protected boolean useSSLTransport()
+ {
+ return false;
+ }
+ }
+
+ /**
+ * @author Teerawat Chaiyakijpichet (No Magic Asia Ltd.)
+ */
+ public static final class SSL extends SignalTest
+ {
+ @Override
+ protected boolean useJVMTransport()
+ {
+ return false;
+ }
+
+ @Override
+ protected boolean useSSLTransport()
+ {
+ return true;
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/TCPConnectorTest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/TCPConnectorTest.java
index 2f4c638e2b..2fc4cc43b4 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/TCPConnectorTest.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/TCPConnectorTest.java
@@ -1,637 +1,637 @@
-/*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- * Teerawat Chaiyakijpichet (No Magic Asia Ltd.) - SSL
- */
-package org.eclipse.net4j.tests;
-
-import org.eclipse.net4j.Net4jUtil;
-import org.eclipse.net4j.buffer.IBufferPool;
-import org.eclipse.net4j.channel.IChannel;
-import org.eclipse.net4j.connector.ConnectorException;
-import org.eclipse.net4j.connector.IConnector;
-import org.eclipse.net4j.internal.tcp.TCPAcceptor;
-import org.eclipse.net4j.internal.tcp.TCPAcceptorFactory;
-import org.eclipse.net4j.internal.tcp.TCPClientConnector;
-import org.eclipse.net4j.internal.tcp.TCPConnector;
-import org.eclipse.net4j.internal.tcp.TCPConnectorFactory;
-import org.eclipse.net4j.internal.tcp.TCPSelector;
-import org.eclipse.net4j.internal.tcp.ssl.SSLAcceptor;
-import org.eclipse.net4j.internal.tcp.ssl.SSLAcceptorFactory;
-import org.eclipse.net4j.internal.tcp.ssl.SSLClientConnector;
-import org.eclipse.net4j.internal.tcp.ssl.SSLConnectorFactory;
-import org.eclipse.net4j.tcp.ITCPSelector;
-import org.eclipse.net4j.tests.bundle.OM;
-import org.eclipse.net4j.util.collection.RoundRobinBlockingQueue;
-import org.eclipse.net4j.util.concurrent.ConcurrencyUtil;
-import org.eclipse.net4j.util.io.IOUtil;
-import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
-import org.eclipse.net4j.util.security.ChallengeNegotiator;
-import org.eclipse.net4j.util.security.NegotiationException;
-import org.eclipse.net4j.util.security.PasswordCredentials;
-import org.eclipse.net4j.util.security.PasswordCredentialsProvider;
-import org.eclipse.net4j.util.security.Randomizer;
-import org.eclipse.net4j.util.security.ResponseNegotiator;
-import org.eclipse.net4j.util.security.UserManager;
-
-import org.eclipse.spi.net4j.Channel;
-import org.eclipse.spi.net4j.InternalChannel;
-
-import java.nio.channels.ServerSocketChannel;
-import java.util.concurrent.BlockingQueue;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-
-/**
- * @author Eike Stepper
- * @author Teerawat Chaiyakijpichet (No Magic Asia Ltd.)
- */
-public class TCPConnectorTest extends AbstractTransportTest
-{
- private static final int TIMEOUT = 10000;
-
- private static final int PORT = 2040;
-
- private static final String USER_ID = "stepper"; //$NON-NLS-1$
-
- private static final String INVALID_USER_ID = "invalid"; //$NON-NLS-1$
-
- private static final char[] PASSWORD = "eike2008".toCharArray(); //$NON-NLS-1$
-
- private static final char[] INVALID_PASSWORD = "invalid".toCharArray(); //$NON-NLS-1$
-
- private static final PasswordCredentials CREDENTIALS = new PasswordCredentials(USER_ID, PASSWORD);
-
- private ExecutorService threadPool;
-
- private IBufferPool bufferPool;
-
- private TCPSelector selector;
-
- private TCPAcceptor acceptor;
-
- private TCPConnector connector;
-
- private Randomizer randomizer;
-
- private UserManager userManager;
-
- private ChallengeNegotiator challengeNegotiator;
-
- private PasswordCredentialsProvider credentialsProvider;
-
- private ResponseNegotiator responseNegotiator;
-
- @Override
- protected void doTearDown() throws Exception
- {
- cleanup();
- super.doTearDown();
- }
-
- private void cleanup() throws Exception
- {
- sleep(100);
-
- if (connector != null)
- {
- connector.close();
- connector = null;
- }
-
- if (responseNegotiator != null)
- {
- LifecycleUtil.deactivate(responseNegotiator);
- responseNegotiator = null;
- }
-
- if (credentialsProvider != null)
- {
- LifecycleUtil.deactivate(credentialsProvider);
- credentialsProvider = null;
- }
-
- if (acceptor != null)
- {
- acceptor.close();
- acceptor = null;
- }
-
- if (challengeNegotiator != null)
- {
- LifecycleUtil.deactivate(challengeNegotiator);
- challengeNegotiator = null;
- }
-
- if (userManager != null)
- {
- LifecycleUtil.deactivate(userManager);
- userManager = null;
- }
-
- if (randomizer != null)
- {
- LifecycleUtil.deactivate(randomizer);
- randomizer = null;
- }
-
- if (selector != null)
- {
- LifecycleUtil.deactivate(selector);
- selector = null;
- }
-
- if (bufferPool != null)
- {
- LifecycleUtil.deactivate(bufferPool);
- bufferPool = null;
- }
-
- if (threadPool != null)
- {
- LifecycleUtil.deactivate(threadPool);
- threadPool = null;
- }
- }
-
- private void provideTransport()
- {
- selector = new TCPSelector();
-
- if (useSSLTransport())
- {
- acceptor = new SSLAcceptor();
- container.putElement(SSLAcceptorFactory.PRODUCT_GROUP, SSLAcceptorFactory.TYPE, null, acceptor);
-
- // cannot use same container with the acceptor.
- connector = new SSLClientConnector();
- separateContainer.putElement(SSLConnectorFactory.PRODUCT_GROUP, SSLConnectorFactory.TYPE, null, acceptor);
- }
- else
- {
- acceptor = new TCPAcceptor();
- container.putElement(TCPAcceptorFactory.PRODUCT_GROUP, TCPAcceptorFactory.TYPE, null, acceptor);
-
- connector = new TCPClientConnector();
- container.putElement(TCPConnectorFactory.PRODUCT_GROUP, TCPConnectorFactory.TYPE, null, acceptor);
- }
- }
-
- private void provideTransport(final long increaseDelayAcceptor)
- {
- selector = new TCPSelector();
-
- if (useSSLTransport())
- {
- acceptor = new SSLAcceptor()
- {
- @Override
- public void handleAccept(ITCPSelector selector, ServerSocketChannel serverSocketChannel)
- {
- ConcurrencyUtil.sleep(increaseDelayAcceptor);
- super.handleAccept(selector, serverSocketChannel);
- }
- };
-
- connector = new SSLClientConnector();
- }
- else
- {
- acceptor = new TCPAcceptor()
- {
- @Override
- public void handleAccept(ITCPSelector selector, ServerSocketChannel serverSocketChannel)
- {
- ConcurrencyUtil.sleep(increaseDelayAcceptor);
- super.handleAccept(selector, serverSocketChannel);
- }
- };
-
- connector = new TCPClientConnector();
- }
- }
-
- public void testDeferredActivation() throws Exception
- {
- final long DELAY = 500L;
- threadPool = Executors.newCachedThreadPool();
- LifecycleUtil.activate(threadPool);
-
- bufferPool = Net4jUtil.createBufferPool();
- LifecycleUtil.activate(bufferPool);
-
- provideTransport(DELAY);
-
- selector.activate();
-
- acceptor.setStartSynchronously(true);
- acceptor.setSynchronousStartTimeout(TIMEOUT);
- acceptor.getConfig().setBufferProvider(bufferPool);
- acceptor.getConfig().setReceiveExecutor(threadPool);
- acceptor.setSelector(selector);
- acceptor.setAddress("0.0.0.0"); //$NON-NLS-1$
- acceptor.setPort(PORT);
- acceptor.activate();
-
- connector.getConfig().setBufferProvider(bufferPool);
- connector.getConfig().setReceiveExecutor(threadPool);
- connector.setSelector(selector);
- connector.setHost("localhost"); //$NON-NLS-1$
- connector.setPort(PORT);
- connector.activate();
- // Can fail due to timing variations: assertEquals(false, connector.isActive());
-
- connector.waitForConnection(DEFAULT_TIMEOUT);
- assertEquals(true, connector.isActive());
- }
-
- public void testDeferredActivation10() throws Exception
- {
- for (int i = 0; i < 10; i++)
- {
- IOUtil.OUT().println();
- IOUtil.OUT().println();
- IOUtil.OUT().println();
- IOUtil.OUT().println("#####################################################"); //$NON-NLS-1$
- IOUtil.OUT().println(" RUN = " + i); //$NON-NLS-1$
- IOUtil.OUT().println("#####################################################"); //$NON-NLS-1$
- IOUtil.OUT().println();
- IOUtil.OUT().println();
- IOUtil.OUT().println();
- testDeferredActivation();
- cleanup();
- }
- }
-
- public void testNegotiationSuccess() throws Exception
- {
- threadPool = Executors.newCachedThreadPool();
- LifecycleUtil.activate(threadPool);
-
- bufferPool = Net4jUtil.createBufferPool();
- LifecycleUtil.activate(bufferPool);
-
- randomizer = new Randomizer();
- randomizer.activate();
-
- userManager = new UserManager();
- userManager.activate();
- userManager.addUser(USER_ID, PASSWORD);
-
- challengeNegotiator = new ChallengeNegotiator();
- challengeNegotiator.setRandomizer(randomizer);
- challengeNegotiator.setUserManager(userManager);
- challengeNegotiator.activate();
-
- provideTransport();
-
- selector.activate();
-
- acceptor.setStartSynchronously(true);
- acceptor.setSynchronousStartTimeout(TIMEOUT);
- acceptor.getConfig().setBufferProvider(bufferPool);
- acceptor.getConfig().setReceiveExecutor(threadPool);
- acceptor.getConfig().setNegotiator(challengeNegotiator);
- acceptor.setSelector(selector);
- acceptor.setAddress("0.0.0.0"); //$NON-NLS-1$
- acceptor.setPort(PORT);
- acceptor.activate();
-
- credentialsProvider = new PasswordCredentialsProvider(CREDENTIALS);
- LifecycleUtil.activate(credentialsProvider);
-
- responseNegotiator = new ResponseNegotiator();
- responseNegotiator.setCredentialsProvider(credentialsProvider);
- responseNegotiator.activate();
-
- connector.getConfig().setBufferProvider(bufferPool);
- connector.getConfig().setReceiveExecutor(threadPool);
- connector.getConfig().setNegotiator(responseNegotiator);
- connector.setSelector(selector);
- connector.setHost("localhost"); //$NON-NLS-1$
- connector.setPort(PORT);
- connector.activate();
-
- connector.waitForConnection(DEFAULT_TIMEOUT);
-
- InternalChannel clientChannel = connector.openChannel();
- assertEquals(USER_ID, clientChannel.getUserID());
-
- IConnector serverConnector = acceptor.getElements()[0];
- IChannel serverChannel = serverConnector.getElements()[0];
- assertEquals(USER_ID, serverChannel.getUserID());
-
- System.out.println(serverChannel);
- }
-
- public void testNegotiationSuccess10() throws Exception
- {
- for (int i = 0; i < 10; i++)
- {
- IOUtil.OUT().println();
- IOUtil.OUT().println();
- IOUtil.OUT().println();
- IOUtil.OUT().println("#####################################################"); //$NON-NLS-1$
- IOUtil.OUT().println(" RUN = " + i); //$NON-NLS-1$
- IOUtil.OUT().println("#####################################################"); //$NON-NLS-1$
- IOUtil.OUT().println();
- IOUtil.OUT().println();
- IOUtil.OUT().println();
- testNegotiationSuccess();
- cleanup();
- }
- }
-
- public void testInvalidUser() throws Exception
- {
- threadPool = Executors.newCachedThreadPool();
- LifecycleUtil.activate(threadPool);
-
- bufferPool = Net4jUtil.createBufferPool();
- LifecycleUtil.activate(bufferPool);
-
- randomizer = new Randomizer();
- randomizer.activate();
-
- userManager = new UserManager();
- userManager.activate();
- userManager.addUser(INVALID_USER_ID, PASSWORD);
-
- challengeNegotiator = new ChallengeNegotiator();
- challengeNegotiator.setRandomizer(randomizer);
- challengeNegotiator.setUserManager(userManager);
- challengeNegotiator.activate();
-
- provideTransport();
-
- selector.activate();
-
- acceptor.setStartSynchronously(true);
- acceptor.setSynchronousStartTimeout(TIMEOUT);
- acceptor.getConfig().setBufferProvider(bufferPool);
- acceptor.getConfig().setReceiveExecutor(threadPool);
- acceptor.getConfig().setNegotiator(challengeNegotiator);
- acceptor.setSelector(selector);
- acceptor.setAddress("0.0.0.0"); //$NON-NLS-1$
- acceptor.setPort(PORT);
- acceptor.activate();
-
- credentialsProvider = new PasswordCredentialsProvider(CREDENTIALS);
- LifecycleUtil.activate(credentialsProvider);
-
- responseNegotiator = new ResponseNegotiator();
- responseNegotiator.setCredentialsProvider(credentialsProvider);
- responseNegotiator.activate();
-
- connector.getConfig().setBufferProvider(bufferPool);
- connector.getConfig().setReceiveExecutor(threadPool);
- connector.getConfig().setNegotiator(responseNegotiator);
- connector.setSelector(selector);
- connector.setHost("localhost"); //$NON-NLS-1$
- connector.setPort(PORT);
-
- try
- {
- connector.connectAsync();
- connector.waitForConnection(DEFAULT_TIMEOUT_EXPECTED);
- fail("ConnectorException expected"); //$NON-NLS-1$
- }
- catch (ConnectorException ex)
- {
- OM.LOG.info("Expected ConnectorException:", ex); //$NON-NLS-1$
- assertEquals(true, ex.getCause() instanceof NegotiationException);
- }
- }
-
- public void testInvalidPassword() throws Exception
- {
- threadPool = Executors.newCachedThreadPool();
- LifecycleUtil.activate(threadPool);
-
- bufferPool = Net4jUtil.createBufferPool();
- LifecycleUtil.activate(bufferPool);
-
- randomizer = new Randomizer();
- randomizer.activate();
-
- userManager = new UserManager();
- userManager.activate();
- userManager.addUser(USER_ID, INVALID_PASSWORD);
-
- challengeNegotiator = new ChallengeNegotiator();
- challengeNegotiator.setRandomizer(randomizer);
- challengeNegotiator.setUserManager(userManager);
- challengeNegotiator.activate();
-
- provideTransport();
-
- selector.activate();
-
- acceptor.setStartSynchronously(true);
- acceptor.setSynchronousStartTimeout(TIMEOUT);
- acceptor.getConfig().setBufferProvider(bufferPool);
- acceptor.getConfig().setReceiveExecutor(threadPool);
- acceptor.getConfig().setNegotiator(challengeNegotiator);
- acceptor.setSelector(selector);
- acceptor.setAddress("0.0.0.0"); //$NON-NLS-1$
- acceptor.setPort(PORT);
- acceptor.activate();
-
- credentialsProvider = new PasswordCredentialsProvider(CREDENTIALS);
- LifecycleUtil.activate(credentialsProvider);
-
- responseNegotiator = new ResponseNegotiator();
- responseNegotiator.setCredentialsProvider(credentialsProvider);
- responseNegotiator.activate();
-
- connector.getConfig().setBufferProvider(bufferPool);
- connector.getConfig().setReceiveExecutor(threadPool);
- connector.getConfig().setNegotiator(responseNegotiator);
- connector.setSelector(selector);
- connector.setHost("localhost"); //$NON-NLS-1$
- connector.setPort(PORT);
-
- try
- {
- connector.connectAsync();
- connector.waitForConnection(DEFAULT_TIMEOUT_EXPECTED);
- fail("ConnectorException expected"); //$NON-NLS-1$
- }
- catch (ConnectorException ex)
- {
- OM.LOG.info("Expected ConnectorException:", ex); //$NON-NLS-1$
- assertEquals(true, ex.getCause() instanceof NegotiationException);
- }
- }
-
- public void testNoNegotiator() throws Exception
- {
- threadPool = Executors.newCachedThreadPool();
- LifecycleUtil.activate(threadPool);
-
- bufferPool = Net4jUtil.createBufferPool();
- LifecycleUtil.activate(bufferPool);
-
- provideTransport();
-
- selector.activate();
-
- acceptor.setStartSynchronously(true);
- acceptor.setSynchronousStartTimeout(TIMEOUT);
- acceptor.getConfig().setBufferProvider(bufferPool);
- acceptor.getConfig().setReceiveExecutor(threadPool);
- acceptor.setSelector(selector);
- acceptor.setAddress("0.0.0.0"); //$NON-NLS-1$
- acceptor.setPort(PORT);
- acceptor.activate();
-
- connector.getConfig().setBufferProvider(bufferPool);
- connector.getConfig().setReceiveExecutor(threadPool);
- connector.setSelector(selector);
- connector.setHost("localhost"); //$NON-NLS-1$
- connector.setPort(PORT);
- connector.setUserID("SHOULD_FAIL_LATER"); //$NON-NLS-1$
-
- try
- {
- connector.connect();
- fail("ConnectorException expected"); //$NON-NLS-1$
- }
- catch (ConnectorException ex)
- {
- OM.LOG.info("Expected ConnectorException:", ex); //$NON-NLS-1$
- assertEquals(true, ex.getCause() instanceof IllegalStateException);
- }
- }
-
- public void testNegotiatorTooLate() throws Exception
- {
- threadPool = Executors.newCachedThreadPool();
- LifecycleUtil.activate(threadPool);
-
- bufferPool = Net4jUtil.createBufferPool();
- LifecycleUtil.activate(bufferPool);
-
- provideTransport();
-
- selector.activate();
-
- acceptor.setStartSynchronously(true);
- acceptor.setSynchronousStartTimeout(TIMEOUT);
- acceptor.getConfig().setBufferProvider(bufferPool);
- acceptor.getConfig().setReceiveExecutor(threadPool);
- acceptor.setSelector(selector);
- acceptor.setAddress("0.0.0.0"); //$NON-NLS-1$
- acceptor.setPort(PORT);
- acceptor.activate();
-
- connector.getConfig().setBufferProvider(bufferPool);
- connector.getConfig().setReceiveExecutor(threadPool);
- connector.setSelector(selector);
- connector.setHost("localhost"); //$NON-NLS-1$
- connector.setPort(PORT);
- connector.connect();
-
- credentialsProvider = new PasswordCredentialsProvider(CREDENTIALS);
- LifecycleUtil.activate(credentialsProvider);
-
- responseNegotiator = new ResponseNegotiator();
- responseNegotiator.setCredentialsProvider(credentialsProvider);
- responseNegotiator.activate();
-
- try
- {
- connector.getConfig().setNegotiator(responseNegotiator);
- fail("IllegalStateException expected"); //$NON-NLS-1$
- }
- catch (IllegalStateException ex)
- {
- OM.LOG.info("Expected IllegalStateException:", ex); //$NON-NLS-1$
- }
- }
-
- public void testRoundRobinBlockingQueue() throws Exception
- {
- BlockingQueue<IChannel> queue = new RoundRobinBlockingQueue<IChannel>();
-
- Channel[] channels = new Channel[3];
-
- for (int i = 0; i < channels.length; i++)
- {
- Channel c = new Channel();
- c.setID((short)i);
- channels[i] = c;
- }
-
- assertEquals(true, queue.isEmpty());
- assertNull(queue.peek());
- assertNull(queue.poll());
-
- // Order will be 0000...1111...2222...
- for (int i = 0; i < channels.length; i++)
- {
- for (int j = 0; j < 10; j++)
- {
- queue.put(channels[i]);
- }
- }
-
- for (int i = 0; i < 30; i++)
- {
- IChannel peek1 = queue.peek();
- IChannel peek2 = queue.peek();
- assertSame(peek1, peek2);
-
- IChannel poll = queue.poll();
- // The order should be 012012012012...
- assertEquals(i % 3, poll.getID());
- assertSame(peek1, poll);
- }
-
- assertEquals(true, queue.isEmpty());
- assertNull(queue.peek());
- assertNull(queue.poll());
- }
-
- /**
- * @author Teerawat Chaiyakijpichet (No Magic Asia Ltd.)
- */
- public static final class TCP extends TCPConnectorTest
- {
- @Override
- protected boolean useJVMTransport()
- {
- return false;
- }
-
- @Override
- protected boolean useSSLTransport()
- {
- return false;
- }
- }
-
- /**
- * @author Teerawat Chaiyakijpichet (No Magic Asia Ltd.)
- */
- public static final class SSL extends TCPConnectorTest
- {
- @Override
- protected boolean useJVMTransport()
- {
- return false;
- }
-
- @Override
- protected boolean useSSLTransport()
- {
- return true;
- }
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ * Teerawat Chaiyakijpichet (No Magic Asia Ltd.) - SSL
+ */
+package org.eclipse.net4j.tests;
+
+import org.eclipse.net4j.Net4jUtil;
+import org.eclipse.net4j.buffer.IBufferPool;
+import org.eclipse.net4j.channel.IChannel;
+import org.eclipse.net4j.connector.ConnectorException;
+import org.eclipse.net4j.connector.IConnector;
+import org.eclipse.net4j.internal.tcp.TCPAcceptor;
+import org.eclipse.net4j.internal.tcp.TCPAcceptorFactory;
+import org.eclipse.net4j.internal.tcp.TCPClientConnector;
+import org.eclipse.net4j.internal.tcp.TCPConnector;
+import org.eclipse.net4j.internal.tcp.TCPConnectorFactory;
+import org.eclipse.net4j.internal.tcp.TCPSelector;
+import org.eclipse.net4j.internal.tcp.ssl.SSLAcceptor;
+import org.eclipse.net4j.internal.tcp.ssl.SSLAcceptorFactory;
+import org.eclipse.net4j.internal.tcp.ssl.SSLClientConnector;
+import org.eclipse.net4j.internal.tcp.ssl.SSLConnectorFactory;
+import org.eclipse.net4j.tcp.ITCPSelector;
+import org.eclipse.net4j.tests.bundle.OM;
+import org.eclipse.net4j.util.collection.RoundRobinBlockingQueue;
+import org.eclipse.net4j.util.concurrent.ConcurrencyUtil;
+import org.eclipse.net4j.util.io.IOUtil;
+import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
+import org.eclipse.net4j.util.security.ChallengeNegotiator;
+import org.eclipse.net4j.util.security.NegotiationException;
+import org.eclipse.net4j.util.security.PasswordCredentials;
+import org.eclipse.net4j.util.security.PasswordCredentialsProvider;
+import org.eclipse.net4j.util.security.Randomizer;
+import org.eclipse.net4j.util.security.ResponseNegotiator;
+import org.eclipse.net4j.util.security.UserManager;
+
+import org.eclipse.spi.net4j.Channel;
+import org.eclipse.spi.net4j.InternalChannel;
+
+import java.nio.channels.ServerSocketChannel;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+/**
+ * @author Eike Stepper
+ * @author Teerawat Chaiyakijpichet (No Magic Asia Ltd.)
+ */
+public class TCPConnectorTest extends AbstractTransportTest
+{
+ private static final int TIMEOUT = 10000;
+
+ private static final int PORT = 2040;
+
+ private static final String USER_ID = "stepper"; //$NON-NLS-1$
+
+ private static final String INVALID_USER_ID = "invalid"; //$NON-NLS-1$
+
+ private static final char[] PASSWORD = "eike2008".toCharArray(); //$NON-NLS-1$
+
+ private static final char[] INVALID_PASSWORD = "invalid".toCharArray(); //$NON-NLS-1$
+
+ private static final PasswordCredentials CREDENTIALS = new PasswordCredentials(USER_ID, PASSWORD);
+
+ private ExecutorService threadPool;
+
+ private IBufferPool bufferPool;
+
+ private TCPSelector selector;
+
+ private TCPAcceptor acceptor;
+
+ private TCPConnector connector;
+
+ private Randomizer randomizer;
+
+ private UserManager userManager;
+
+ private ChallengeNegotiator challengeNegotiator;
+
+ private PasswordCredentialsProvider credentialsProvider;
+
+ private ResponseNegotiator responseNegotiator;
+
+ @Override
+ protected void doTearDown() throws Exception
+ {
+ cleanup();
+ super.doTearDown();
+ }
+
+ private void cleanup() throws Exception
+ {
+ sleep(100);
+
+ if (connector != null)
+ {
+ connector.close();
+ connector = null;
+ }
+
+ if (responseNegotiator != null)
+ {
+ LifecycleUtil.deactivate(responseNegotiator);
+ responseNegotiator = null;
+ }
+
+ if (credentialsProvider != null)
+ {
+ LifecycleUtil.deactivate(credentialsProvider);
+ credentialsProvider = null;
+ }
+
+ if (acceptor != null)
+ {
+ acceptor.close();
+ acceptor = null;
+ }
+
+ if (challengeNegotiator != null)
+ {
+ LifecycleUtil.deactivate(challengeNegotiator);
+ challengeNegotiator = null;
+ }
+
+ if (userManager != null)
+ {
+ LifecycleUtil.deactivate(userManager);
+ userManager = null;
+ }
+
+ if (randomizer != null)
+ {
+ LifecycleUtil.deactivate(randomizer);
+ randomizer = null;
+ }
+
+ if (selector != null)
+ {
+ LifecycleUtil.deactivate(selector);
+ selector = null;
+ }
+
+ if (bufferPool != null)
+ {
+ LifecycleUtil.deactivate(bufferPool);
+ bufferPool = null;
+ }
+
+ if (threadPool != null)
+ {
+ LifecycleUtil.deactivate(threadPool);
+ threadPool = null;
+ }
+ }
+
+ private void provideTransport()
+ {
+ selector = new TCPSelector();
+
+ if (useSSLTransport())
+ {
+ acceptor = new SSLAcceptor();
+ container.putElement(SSLAcceptorFactory.PRODUCT_GROUP, SSLAcceptorFactory.TYPE, null, acceptor);
+
+ // cannot use same container with the acceptor.
+ connector = new SSLClientConnector();
+ separateContainer.putElement(SSLConnectorFactory.PRODUCT_GROUP, SSLConnectorFactory.TYPE, null, acceptor);
+ }
+ else
+ {
+ acceptor = new TCPAcceptor();
+ container.putElement(TCPAcceptorFactory.PRODUCT_GROUP, TCPAcceptorFactory.TYPE, null, acceptor);
+
+ connector = new TCPClientConnector();
+ container.putElement(TCPConnectorFactory.PRODUCT_GROUP, TCPConnectorFactory.TYPE, null, acceptor);
+ }
+ }
+
+ private void provideTransport(final long increaseDelayAcceptor)
+ {
+ selector = new TCPSelector();
+
+ if (useSSLTransport())
+ {
+ acceptor = new SSLAcceptor()
+ {
+ @Override
+ public void handleAccept(ITCPSelector selector, ServerSocketChannel serverSocketChannel)
+ {
+ ConcurrencyUtil.sleep(increaseDelayAcceptor);
+ super.handleAccept(selector, serverSocketChannel);
+ }
+ };
+
+ connector = new SSLClientConnector();
+ }
+ else
+ {
+ acceptor = new TCPAcceptor()
+ {
+ @Override
+ public void handleAccept(ITCPSelector selector, ServerSocketChannel serverSocketChannel)
+ {
+ ConcurrencyUtil.sleep(increaseDelayAcceptor);
+ super.handleAccept(selector, serverSocketChannel);
+ }
+ };
+
+ connector = new TCPClientConnector();
+ }
+ }
+
+ public void testDeferredActivation() throws Exception
+ {
+ final long DELAY = 500L;
+ threadPool = Executors.newCachedThreadPool();
+ LifecycleUtil.activate(threadPool);
+
+ bufferPool = Net4jUtil.createBufferPool();
+ LifecycleUtil.activate(bufferPool);
+
+ provideTransport(DELAY);
+
+ selector.activate();
+
+ acceptor.setStartSynchronously(true);
+ acceptor.setSynchronousStartTimeout(TIMEOUT);
+ acceptor.getConfig().setBufferProvider(bufferPool);
+ acceptor.getConfig().setReceiveExecutor(threadPool);
+ acceptor.setSelector(selector);
+ acceptor.setAddress("0.0.0.0"); //$NON-NLS-1$
+ acceptor.setPort(PORT);
+ acceptor.activate();
+
+ connector.getConfig().setBufferProvider(bufferPool);
+ connector.getConfig().setReceiveExecutor(threadPool);
+ connector.setSelector(selector);
+ connector.setHost("localhost"); //$NON-NLS-1$
+ connector.setPort(PORT);
+ connector.activate();
+ // Can fail due to timing variations: assertEquals(false, connector.isActive());
+
+ connector.waitForConnection(DEFAULT_TIMEOUT);
+ assertEquals(true, connector.isActive());
+ }
+
+ public void testDeferredActivation10() throws Exception
+ {
+ for (int i = 0; i < 10; i++)
+ {
+ IOUtil.OUT().println();
+ IOUtil.OUT().println();
+ IOUtil.OUT().println();
+ IOUtil.OUT().println("#####################################################"); //$NON-NLS-1$
+ IOUtil.OUT().println(" RUN = " + i); //$NON-NLS-1$
+ IOUtil.OUT().println("#####################################################"); //$NON-NLS-1$
+ IOUtil.OUT().println();
+ IOUtil.OUT().println();
+ IOUtil.OUT().println();
+ testDeferredActivation();
+ cleanup();
+ }
+ }
+
+ public void testNegotiationSuccess() throws Exception
+ {
+ threadPool = Executors.newCachedThreadPool();
+ LifecycleUtil.activate(threadPool);
+
+ bufferPool = Net4jUtil.createBufferPool();
+ LifecycleUtil.activate(bufferPool);
+
+ randomizer = new Randomizer();
+ randomizer.activate();
+
+ userManager = new UserManager();
+ userManager.activate();
+ userManager.addUser(USER_ID, PASSWORD);
+
+ challengeNegotiator = new ChallengeNegotiator();
+ challengeNegotiator.setRandomizer(randomizer);
+ challengeNegotiator.setUserManager(userManager);
+ challengeNegotiator.activate();
+
+ provideTransport();
+
+ selector.activate();
+
+ acceptor.setStartSynchronously(true);
+ acceptor.setSynchronousStartTimeout(TIMEOUT);
+ acceptor.getConfig().setBufferProvider(bufferPool);
+ acceptor.getConfig().setReceiveExecutor(threadPool);
+ acceptor.getConfig().setNegotiator(challengeNegotiator);
+ acceptor.setSelector(selector);
+ acceptor.setAddress("0.0.0.0"); //$NON-NLS-1$
+ acceptor.setPort(PORT);
+ acceptor.activate();
+
+ credentialsProvider = new PasswordCredentialsProvider(CREDENTIALS);
+ LifecycleUtil.activate(credentialsProvider);
+
+ responseNegotiator = new ResponseNegotiator();
+ responseNegotiator.setCredentialsProvider(credentialsProvider);
+ responseNegotiator.activate();
+
+ connector.getConfig().setBufferProvider(bufferPool);
+ connector.getConfig().setReceiveExecutor(threadPool);
+ connector.getConfig().setNegotiator(responseNegotiator);
+ connector.setSelector(selector);
+ connector.setHost("localhost"); //$NON-NLS-1$
+ connector.setPort(PORT);
+ connector.activate();
+
+ connector.waitForConnection(DEFAULT_TIMEOUT);
+
+ InternalChannel clientChannel = connector.openChannel();
+ assertEquals(USER_ID, clientChannel.getUserID());
+
+ IConnector serverConnector = acceptor.getElements()[0];
+ IChannel serverChannel = serverConnector.getElements()[0];
+ assertEquals(USER_ID, serverChannel.getUserID());
+
+ System.out.println(serverChannel);
+ }
+
+ public void testNegotiationSuccess10() throws Exception
+ {
+ for (int i = 0; i < 10; i++)
+ {
+ IOUtil.OUT().println();
+ IOUtil.OUT().println();
+ IOUtil.OUT().println();
+ IOUtil.OUT().println("#####################################################"); //$NON-NLS-1$
+ IOUtil.OUT().println(" RUN = " + i); //$NON-NLS-1$
+ IOUtil.OUT().println("#####################################################"); //$NON-NLS-1$
+ IOUtil.OUT().println();
+ IOUtil.OUT().println();
+ IOUtil.OUT().println();
+ testNegotiationSuccess();
+ cleanup();
+ }
+ }
+
+ public void testInvalidUser() throws Exception
+ {
+ threadPool = Executors.newCachedThreadPool();
+ LifecycleUtil.activate(threadPool);
+
+ bufferPool = Net4jUtil.createBufferPool();
+ LifecycleUtil.activate(bufferPool);
+
+ randomizer = new Randomizer();
+ randomizer.activate();
+
+ userManager = new UserManager();
+ userManager.activate();
+ userManager.addUser(INVALID_USER_ID, PASSWORD);
+
+ challengeNegotiator = new ChallengeNegotiator();
+ challengeNegotiator.setRandomizer(randomizer);
+ challengeNegotiator.setUserManager(userManager);
+ challengeNegotiator.activate();
+
+ provideTransport();
+
+ selector.activate();
+
+ acceptor.setStartSynchronously(true);
+ acceptor.setSynchronousStartTimeout(TIMEOUT);
+ acceptor.getConfig().setBufferProvider(bufferPool);
+ acceptor.getConfig().setReceiveExecutor(threadPool);
+ acceptor.getConfig().setNegotiator(challengeNegotiator);
+ acceptor.setSelector(selector);
+ acceptor.setAddress("0.0.0.0"); //$NON-NLS-1$
+ acceptor.setPort(PORT);
+ acceptor.activate();
+
+ credentialsProvider = new PasswordCredentialsProvider(CREDENTIALS);
+ LifecycleUtil.activate(credentialsProvider);
+
+ responseNegotiator = new ResponseNegotiator();
+ responseNegotiator.setCredentialsProvider(credentialsProvider);
+ responseNegotiator.activate();
+
+ connector.getConfig().setBufferProvider(bufferPool);
+ connector.getConfig().setReceiveExecutor(threadPool);
+ connector.getConfig().setNegotiator(responseNegotiator);
+ connector.setSelector(selector);
+ connector.setHost("localhost"); //$NON-NLS-1$
+ connector.setPort(PORT);
+
+ try
+ {
+ connector.connectAsync();
+ connector.waitForConnection(DEFAULT_TIMEOUT_EXPECTED);
+ fail("ConnectorException expected"); //$NON-NLS-1$
+ }
+ catch (ConnectorException ex)
+ {
+ OM.LOG.info("Expected ConnectorException:", ex); //$NON-NLS-1$
+ assertEquals(true, ex.getCause() instanceof NegotiationException);
+ }
+ }
+
+ public void testInvalidPassword() throws Exception
+ {
+ threadPool = Executors.newCachedThreadPool();
+ LifecycleUtil.activate(threadPool);
+
+ bufferPool = Net4jUtil.createBufferPool();
+ LifecycleUtil.activate(bufferPool);
+
+ randomizer = new Randomizer();
+ randomizer.activate();
+
+ userManager = new UserManager();
+ userManager.activate();
+ userManager.addUser(USER_ID, INVALID_PASSWORD);
+
+ challengeNegotiator = new ChallengeNegotiator();
+ challengeNegotiator.setRandomizer(randomizer);
+ challengeNegotiator.setUserManager(userManager);
+ challengeNegotiator.activate();
+
+ provideTransport();
+
+ selector.activate();
+
+ acceptor.setStartSynchronously(true);
+ acceptor.setSynchronousStartTimeout(TIMEOUT);
+ acceptor.getConfig().setBufferProvider(bufferPool);
+ acceptor.getConfig().setReceiveExecutor(threadPool);
+ acceptor.getConfig().setNegotiator(challengeNegotiator);
+ acceptor.setSelector(selector);
+ acceptor.setAddress("0.0.0.0"); //$NON-NLS-1$
+ acceptor.setPort(PORT);
+ acceptor.activate();
+
+ credentialsProvider = new PasswordCredentialsProvider(CREDENTIALS);
+ LifecycleUtil.activate(credentialsProvider);
+
+ responseNegotiator = new ResponseNegotiator();
+ responseNegotiator.setCredentialsProvider(credentialsProvider);
+ responseNegotiator.activate();
+
+ connector.getConfig().setBufferProvider(bufferPool);
+ connector.getConfig().setReceiveExecutor(threadPool);
+ connector.getConfig().setNegotiator(responseNegotiator);
+ connector.setSelector(selector);
+ connector.setHost("localhost"); //$NON-NLS-1$
+ connector.setPort(PORT);
+
+ try
+ {
+ connector.connectAsync();
+ connector.waitForConnection(DEFAULT_TIMEOUT_EXPECTED);
+ fail("ConnectorException expected"); //$NON-NLS-1$
+ }
+ catch (ConnectorException ex)
+ {
+ OM.LOG.info("Expected ConnectorException:", ex); //$NON-NLS-1$
+ assertEquals(true, ex.getCause() instanceof NegotiationException);
+ }
+ }
+
+ public void testNoNegotiator() throws Exception
+ {
+ threadPool = Executors.newCachedThreadPool();
+ LifecycleUtil.activate(threadPool);
+
+ bufferPool = Net4jUtil.createBufferPool();
+ LifecycleUtil.activate(bufferPool);
+
+ provideTransport();
+
+ selector.activate();
+
+ acceptor.setStartSynchronously(true);
+ acceptor.setSynchronousStartTimeout(TIMEOUT);
+ acceptor.getConfig().setBufferProvider(bufferPool);
+ acceptor.getConfig().setReceiveExecutor(threadPool);
+ acceptor.setSelector(selector);
+ acceptor.setAddress("0.0.0.0"); //$NON-NLS-1$
+ acceptor.setPort(PORT);
+ acceptor.activate();
+
+ connector.getConfig().setBufferProvider(bufferPool);
+ connector.getConfig().setReceiveExecutor(threadPool);
+ connector.setSelector(selector);
+ connector.setHost("localhost"); //$NON-NLS-1$
+ connector.setPort(PORT);
+ connector.setUserID("SHOULD_FAIL_LATER"); //$NON-NLS-1$
+
+ try
+ {
+ connector.connect();
+ fail("ConnectorException expected"); //$NON-NLS-1$
+ }
+ catch (ConnectorException ex)
+ {
+ OM.LOG.info("Expected ConnectorException:", ex); //$NON-NLS-1$
+ assertEquals(true, ex.getCause() instanceof IllegalStateException);
+ }
+ }
+
+ public void testNegotiatorTooLate() throws Exception
+ {
+ threadPool = Executors.newCachedThreadPool();
+ LifecycleUtil.activate(threadPool);
+
+ bufferPool = Net4jUtil.createBufferPool();
+ LifecycleUtil.activate(bufferPool);
+
+ provideTransport();
+
+ selector.activate();
+
+ acceptor.setStartSynchronously(true);
+ acceptor.setSynchronousStartTimeout(TIMEOUT);
+ acceptor.getConfig().setBufferProvider(bufferPool);
+ acceptor.getConfig().setReceiveExecutor(threadPool);
+ acceptor.setSelector(selector);
+ acceptor.setAddress("0.0.0.0"); //$NON-NLS-1$
+ acceptor.setPort(PORT);
+ acceptor.activate();
+
+ connector.getConfig().setBufferProvider(bufferPool);
+ connector.getConfig().setReceiveExecutor(threadPool);
+ connector.setSelector(selector);
+ connector.setHost("localhost"); //$NON-NLS-1$
+ connector.setPort(PORT);
+ connector.connect();
+
+ credentialsProvider = new PasswordCredentialsProvider(CREDENTIALS);
+ LifecycleUtil.activate(credentialsProvider);
+
+ responseNegotiator = new ResponseNegotiator();
+ responseNegotiator.setCredentialsProvider(credentialsProvider);
+ responseNegotiator.activate();
+
+ try
+ {
+ connector.getConfig().setNegotiator(responseNegotiator);
+ fail("IllegalStateException expected"); //$NON-NLS-1$
+ }
+ catch (IllegalStateException ex)
+ {
+ OM.LOG.info("Expected IllegalStateException:", ex); //$NON-NLS-1$
+ }
+ }
+
+ public void testRoundRobinBlockingQueue() throws Exception
+ {
+ BlockingQueue<IChannel> queue = new RoundRobinBlockingQueue<IChannel>();
+
+ Channel[] channels = new Channel[3];
+
+ for (int i = 0; i < channels.length; i++)
+ {
+ Channel c = new Channel();
+ c.setID((short)i);
+ channels[i] = c;
+ }
+
+ assertEquals(true, queue.isEmpty());
+ assertNull(queue.peek());
+ assertNull(queue.poll());
+
+ // Order will be 0000...1111...2222...
+ for (int i = 0; i < channels.length; i++)
+ {
+ for (int j = 0; j < 10; j++)
+ {
+ queue.put(channels[i]);
+ }
+ }
+
+ for (int i = 0; i < 30; i++)
+ {
+ IChannel peek1 = queue.peek();
+ IChannel peek2 = queue.peek();
+ assertSame(peek1, peek2);
+
+ IChannel poll = queue.poll();
+ // The order should be 012012012012...
+ assertEquals(i % 3, poll.getID());
+ assertSame(peek1, poll);
+ }
+
+ assertEquals(true, queue.isEmpty());
+ assertNull(queue.peek());
+ assertNull(queue.poll());
+ }
+
+ /**
+ * @author Teerawat Chaiyakijpichet (No Magic Asia Ltd.)
+ */
+ public static final class TCP extends TCPConnectorTest
+ {
+ @Override
+ protected boolean useJVMTransport()
+ {
+ return false;
+ }
+
+ @Override
+ protected boolean useSSLTransport()
+ {
+ return false;
+ }
+ }
+
+ /**
+ * @author Teerawat Chaiyakijpichet (No Magic Asia Ltd.)
+ */
+ public static final class SSL extends TCPConnectorTest
+ {
+ @Override
+ protected boolean useJVMTransport()
+ {
+ return false;
+ }
+
+ @Override
+ protected boolean useSSLTransport()
+ {
+ return true;
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/TCPUnitTest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/TCPUnitTest.java
index 37d607f77e..3e13bad105 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/TCPUnitTest.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/TCPUnitTest.java
@@ -1,27 +1,27 @@
-/*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- */
-package org.eclipse.net4j.tests;
-
-import org.eclipse.net4j.util.tests.AbstractOMTest;
-
-/**
- * @author Eike Stepper
- */
-public class TCPUnitTest extends AbstractOMTest
-{
- public TCPUnitTest()
- {
- }
-
- public void test()
- {
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.tests;
+
+import org.eclipse.net4j.util.tests.AbstractOMTest;
+
+/**
+ * @author Eike Stepper
+ */
+public class TCPUnitTest extends AbstractOMTest
+{
+ public TCPUnitTest()
+ {
+ }
+
+ public void test()
+ {
+ }
+}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/TransportTest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/TransportTest.java
index 62419f2c1d..bfc34b499b 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/TransportTest.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/TransportTest.java
@@ -1,534 +1,534 @@
-/*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- * Teerawat Chaiyakijpichet (No Magic Asia Ltd.) - SSL
- */
-package org.eclipse.net4j.tests;
-
-import org.eclipse.net4j.Net4jUtil;
-import org.eclipse.net4j.buffer.IBuffer;
-import org.eclipse.net4j.buffer.IBufferProvider;
-import org.eclipse.net4j.channel.ChannelInputStream;
-import org.eclipse.net4j.channel.ChannelOutputStream;
-import org.eclipse.net4j.channel.IChannel;
-import org.eclipse.net4j.connector.IConnector;
-import org.eclipse.net4j.tests.data.HugeData;
-import org.eclipse.net4j.util.container.IContainerDelta;
-import org.eclipse.net4j.util.container.IContainerEvent;
-import org.eclipse.net4j.util.event.IEvent;
-import org.eclipse.net4j.util.event.IListener;
-import org.eclipse.net4j.util.factory.IFactory;
-import org.eclipse.net4j.util.factory.ProductCreationException;
-import org.eclipse.net4j.util.io.IOUtil;
-
-import org.eclipse.spi.net4j.ClientProtocolFactory;
-import org.eclipse.spi.net4j.Connector;
-import org.eclipse.spi.net4j.Protocol;
-import org.eclipse.spi.net4j.ServerProtocolFactory;
-
-import java.io.BufferedReader;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.PrintStream;
-import java.nio.ByteBuffer;
-import java.util.StringTokenizer;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-
-/**
- * @author Eike Stepper
- */
-public abstract class TransportTest extends AbstractProtocolTest
-{
- public TransportTest()
- {
- }
-
- @Override
- protected abstract boolean useJVMTransport();
-
- protected IBuffer provideBuffer()
- {
- return provideBuffer(null);
- }
-
- protected IBuffer provideBuffer(IConnector iConnector)
- {
- IBuffer buffer = null;
- if (!useJVMTransport() && useSSLTransport())
- {
- // cannot use buffer provider from net4j need to use SSL Buffer inside the SSLConnector.
- buffer = ((Connector)iConnector).provideBuffer();
- }
- else
- {
- IBufferProvider bufferProvider = Net4jUtil.getBufferProvider(container);
- buffer = bufferProvider.provideBuffer();
- }
-
- return buffer;
- }
-
- private void registerClientFactory(IFactory factory)
- {
- if (!useJVMTransport() && useSSLTransport())
- {
- // need separate container between client and server for SSL.
- separateContainer.registerFactory(factory);
- }
- else
- {
- container.registerFactory(factory);
- }
- }
-
- protected IBufferProvider provideBufferProvider(IConnector iConnector)
- {
- IBufferProvider bufferProvider = null;
- if (!useJVMTransport() && useSSLTransport())
- {
- // cannot use buffer provider from net4j need to use SSL Buffer inside the SSLConnector.
- bufferProvider = ((Connector)iConnector).getConfig().getBufferProvider();
- }
- else
- {
- bufferProvider = Net4jUtil.getBufferProvider(container);
- }
-
- return bufferProvider;
- }
-
- public void testConnect() throws Exception
- {
- startTransport();
- }
-
- public void testSendBuffer() throws Exception
- {
- startTransport();
- IConnector iConnecter = getConnector();
- IChannel channel = iConnecter.openChannel();
- for (int i = 0; i < 3; i++)
- {
- IBuffer buffer = provideBuffer(iConnecter);
-
- ByteBuffer byteBuffer = buffer.startPutting(channel.getID());
- byteBuffer.putInt(1970);
- channel.sendBuffer(buffer);
- }
- }
-
- public void testHandleBuffer() throws Exception
- {
- final int COUNT = 3;
- final CountDownLatch counter = new CountDownLatch(COUNT);
- container.registerFactory(new TestProtocol.ServerFactory(counter));
- // need to handle about separating container between client and server for SSL.
- registerClientFactory(new TestProtocol.ClientFactory());
- startTransport();
- IConnector iConnecter = getConnector();
- IChannel channel = iConnecter.openChannel(TestProtocol.ClientFactory.TYPE, null);
- for (int i = 0; i < COUNT; i++)
- {
- IBuffer buffer = provideBuffer(iConnecter);
- ByteBuffer byteBuffer = buffer.startPutting(channel.getID());
- byteBuffer.putInt(1970);
- channel.sendBuffer(buffer);
- sleep(50);
- }
-
- assertEquals(true, counter.await(2, TimeUnit.SECONDS));
- }
-
- public void testStreaming() throws Exception
- {
- final int COUNT = 1;
- final CountDownLatch counter = new CountDownLatch(COUNT);
- final ChannelInputStream[] inputStream = new ChannelInputStream[1];
-
- getAcceptor().addListener(new IListener()
- {
- public void notifyEvent(IEvent event)
- {
- if (event instanceof IContainerEvent<?>)
- {
- @SuppressWarnings("unchecked")
- IContainerEvent<IConnector> e = (IContainerEvent<IConnector>)event;
- e.getDeltaElement().addListener(new IListener()
- {
- public void notifyEvent(IEvent event)
- {
- if (event instanceof IContainerEvent<?>)
- {
- @SuppressWarnings("unchecked")
- IContainerEvent<IChannel> e = (IContainerEvent<IChannel>)event;
- if (e.getDeltaKind() == IContainerDelta.Kind.ADDED)
- {
- inputStream[0] = new ChannelInputStream(e.getDeltaElement(), 2000);
- counter.countDown();
- }
- }
- }
- });
- }
- }
- });
-
- IChannel channel = getConnector().openChannel();
- assertEquals(true, counter.await(2, TimeUnit.SECONDS));
- assertNotNull(inputStream[0]);
-
- ChannelOutputStream outputStream = new ChannelOutputStream(channel);
- outputStream.write(HugeData.getBytes());
- outputStream.flushWithEOS();
- outputStream.close();
-
- try
- {
- InputStreamReader isr = new InputStreamReader(inputStream[0]);
- BufferedReader reader = new BufferedReader(isr);
- String line;
- while ((line = reader.readLine()) != null)
- {
- msg(line);
- }
-
- isr.close();
- }
- catch (RuntimeException ex)
- {
- IOUtil.print(ex);
- }
- }
-
- /**
- * TODO Fails occasionally ;-( Caused by: java.lang.IllegalStateException: selectionKey == null
- */
- public void testTextStreaming() throws Exception
- {
- final int COUNT = 1;
- final CountDownLatch counter = new CountDownLatch(COUNT);
- final ChannelInputStream[] inputStream = new ChannelInputStream[1];
-
- getAcceptor().addListener(new IListener()
- {
- public void notifyEvent(IEvent event)
- {
- if (event instanceof IContainerEvent<?>)
- {
- @SuppressWarnings("unchecked")
- IContainerEvent<IConnector> e = (IContainerEvent<IConnector>)event;
- e.getDeltaElement().addListener(new IListener()
- {
- public void notifyEvent(IEvent event)
- {
- if (event instanceof IContainerEvent<?>)
- {
- @SuppressWarnings("unchecked")
- IContainerEvent<IChannel> e = (IContainerEvent<IChannel>)event;
- if (e.getDeltaKind() == IContainerDelta.Kind.ADDED)
- {
- inputStream[0] = new ChannelInputStream(e.getDeltaElement(), 2000);
- counter.countDown();
- }
- }
- }
- });
- }
- }
- });
-
- IChannel channel = getConnector().openChannel();
- assertEquals(true, counter.await(2, TimeUnit.SECONDS));
- assertNotNull(inputStream[0]);
-
- ChannelOutputStream outputStream = new ChannelOutputStream(channel);
- PrintStream printer = new PrintStream(outputStream);
- StringTokenizer tokenizer = HugeData.getTokenizer();
- while (tokenizer.hasMoreTokens())
- {
- String token = tokenizer.nextToken();
- printer.println(token);
- }
-
- outputStream.flushWithEOS();
- outputStream.close();
-
- try
- {
- InputStreamReader isr = new InputStreamReader(inputStream[0]);
- BufferedReader reader = new BufferedReader(isr);
- String line;
- while ((line = reader.readLine()) != null)
- {
- msg(line);
- }
-
- isr.close();
- }
- catch (RuntimeException ex)
- {
- IOUtil.print(ex);
- }
- }
-
- public void testTextStreamingDecoupled() throws Exception
- {
- final int COUNT = 1;
- final CountDownLatch counter = new CountDownLatch(COUNT);
- final ChannelInputStream[] inputStream = new ChannelInputStream[1];
-
- getAcceptor().addListener(new IListener()
- {
- public void notifyEvent(IEvent event)
- {
- if (event instanceof IContainerEvent<?>)
- {
- @SuppressWarnings("unchecked")
- IContainerEvent<IConnector> e = (IContainerEvent<IConnector>)event;
- e.getDeltaElement().addListener(new IListener()
- {
- public void notifyEvent(IEvent event)
- {
- if (event instanceof IContainerEvent<?>)
- {
- @SuppressWarnings("unchecked")
- IContainerEvent<IChannel> e = (IContainerEvent<IChannel>)event;
- if (e.getDeltaKind() == IContainerDelta.Kind.ADDED)
- {
- inputStream[0] = new ChannelInputStream(e.getDeltaElement(), 2000);
- counter.countDown();
- }
- }
- }
- });
- }
- }
- });
-
- final IConnector iConnector = getConnector();
- final IChannel channel = iConnector.openChannel();
- assertEquals(true, counter.await(2, TimeUnit.SECONDS));
- assertNotNull(inputStream[0]);
-
- new Thread()
- {
- @Override
- public void run()
- {
- try
- {
- IBufferProvider bufferProvider = provideBufferProvider(iConnector);
- ChannelOutputStream outputStream = new ChannelOutputStream(channel, bufferProvider);
- PrintStream printer = new PrintStream(outputStream);
- StringTokenizer tokenizer = HugeData.getTokenizer();
- while (tokenizer.hasMoreTokens())
- {
- String token = tokenizer.nextToken();
- printer.println(token);
- }
-
- outputStream.flushWithEOS();
- outputStream.close();
- }
- catch (IOException ex)
- {
- IOUtil.print(ex);
- fail(ex.getLocalizedMessage());
- }
- }
- }.start();
-
- try
- {
- InputStreamReader isr = new InputStreamReader(inputStream[0]);
- BufferedReader reader = new BufferedReader(isr);
- String line;
- while ((line = reader.readLine()) != null)
- {
- msg(line);
- }
-
- isr.close();
- }
- catch (RuntimeException ex)
- {
- IOUtil.print(ex);
- }
- }
-
- public void testDataStreaming() throws Exception
- {
- final int COUNT = 1;
- final CountDownLatch counter = new CountDownLatch(COUNT);
- final ChannelInputStream[] inputStream = new ChannelInputStream[1];
-
- getAcceptor().addListener(new IListener()
- {
- public void notifyEvent(IEvent event)
- {
- if (event instanceof IContainerEvent<?>)
- {
- @SuppressWarnings("unchecked")
- IContainerEvent<IConnector> e = (IContainerEvent<IConnector>)event;
- e.getDeltaElement().addListener(new IListener()
- {
- public void notifyEvent(IEvent event)
- {
- if (event instanceof IContainerEvent<?>)
- {
- @SuppressWarnings("unchecked")
- IContainerEvent<IChannel> e = (IContainerEvent<IChannel>)event;
- if (e.getDeltaKind() == IContainerDelta.Kind.ADDED)
- {
- inputStream[0] = new ChannelInputStream(e.getDeltaElement(), 2000);
- counter.countDown();
- }
- }
- }
- });
- }
- }
- });
-
- IChannel channel = getConnector().openChannel();
- assertEquals(true, counter.await(2, TimeUnit.SECONDS));
-
- ChannelOutputStream outputStream = new ChannelOutputStream(channel);
- DataOutputStream dataOutput = new DataOutputStream(outputStream);
- byte[] data = HugeData.getBytes();
- dataOutput.writeInt(data.length);
- dataOutput.write(data);
- dataOutput.flush();
- dataOutput.close();
- outputStream.flush();
-
- DataInputStream dataInput = new DataInputStream(inputStream[0]);
- int size = dataInput.readInt();
- byte[] b = new byte[size];
- dataInput.read(b);
- dataInput.close();
-
- msg(new String(b));
- }
-
- /**
- * @author Eike Stepper
- */
- public static final class TestProtocol extends Protocol<CountDownLatch>
- {
- public TestProtocol(CountDownLatch counter)
- {
- super(ServerFactory.TYPE);
- setInfraStructure(counter);
- }
-
- public void handleBuffer(IBuffer buffer)
- {
- IOUtil.OUT().println("BUFFER ARRIVED"); //$NON-NLS-1$
- buffer.release();
- getInfraStructure().countDown();
- }
-
- /**
- * @author Eike Stepper
- */
- public static class ServerFactory extends ServerProtocolFactory
- {
- public static final String TYPE = "test.protocol"; //$NON-NLS-1$
-
- private CountDownLatch counter;
-
- public ServerFactory(CountDownLatch counter)
- {
- super(TYPE);
- this.counter = counter;
- }
-
- public TestProtocol create(String description) throws ProductCreationException
- {
- return new TestProtocol(counter);
- }
- }
-
- /**
- * @author Eike Stepper
- */
- public static class ClientFactory extends ClientProtocolFactory
- {
- public static final String TYPE = ServerFactory.TYPE;
-
- public ClientFactory()
- {
- super(TYPE);
- }
-
- public TestProtocol create(String description) throws ProductCreationException
- {
- return new TestProtocol(null);
- }
- }
- }
-
- /**
- * @author Eike Stepper
- */
- public static final class TCP extends TransportTest
- {
- @Override
- protected boolean useJVMTransport()
- {
- return false;
- }
-
- @Override
- protected boolean useSSLTransport()
- {
- return false;
- }
- }
-
- /**
- * @author Eike Stepper
- */
- public static final class JVM extends TransportTest
- {
- @Override
- protected boolean useJVMTransport()
- {
- return true;
- }
-
- @Override
- protected boolean useSSLTransport()
- {
- return false;
- }
- }
-
- /**
- * @author Teerawat Chaiyakijpichet (No Magic Asia Ltd.)
- */
- public static final class SSL extends TransportTest
- {
- @Override
- protected boolean useJVMTransport()
- {
- return false;
- }
-
- @Override
- protected boolean useSSLTransport()
- {
- return true;
- }
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ * Teerawat Chaiyakijpichet (No Magic Asia Ltd.) - SSL
+ */
+package org.eclipse.net4j.tests;
+
+import org.eclipse.net4j.Net4jUtil;
+import org.eclipse.net4j.buffer.IBuffer;
+import org.eclipse.net4j.buffer.IBufferProvider;
+import org.eclipse.net4j.channel.ChannelInputStream;
+import org.eclipse.net4j.channel.ChannelOutputStream;
+import org.eclipse.net4j.channel.IChannel;
+import org.eclipse.net4j.connector.IConnector;
+import org.eclipse.net4j.tests.data.HugeData;
+import org.eclipse.net4j.util.container.IContainerDelta;
+import org.eclipse.net4j.util.container.IContainerEvent;
+import org.eclipse.net4j.util.event.IEvent;
+import org.eclipse.net4j.util.event.IListener;
+import org.eclipse.net4j.util.factory.IFactory;
+import org.eclipse.net4j.util.factory.ProductCreationException;
+import org.eclipse.net4j.util.io.IOUtil;
+
+import org.eclipse.spi.net4j.ClientProtocolFactory;
+import org.eclipse.spi.net4j.Connector;
+import org.eclipse.spi.net4j.Protocol;
+import org.eclipse.spi.net4j.ServerProtocolFactory;
+
+import java.io.BufferedReader;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.PrintStream;
+import java.nio.ByteBuffer;
+import java.util.StringTokenizer;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * @author Eike Stepper
+ */
+public abstract class TransportTest extends AbstractProtocolTest
+{
+ public TransportTest()
+ {
+ }
+
+ @Override
+ protected abstract boolean useJVMTransport();
+
+ protected IBuffer provideBuffer()
+ {
+ return provideBuffer(null);
+ }
+
+ protected IBuffer provideBuffer(IConnector iConnector)
+ {
+ IBuffer buffer = null;
+ if (!useJVMTransport() && useSSLTransport())
+ {
+ // cannot use buffer provider from net4j need to use SSL Buffer inside the SSLConnector.
+ buffer = ((Connector)iConnector).provideBuffer();
+ }
+ else
+ {
+ IBufferProvider bufferProvider = Net4jUtil.getBufferProvider(container);
+ buffer = bufferProvider.provideBuffer();
+ }
+
+ return buffer;
+ }
+
+ private void registerClientFactory(IFactory factory)
+ {
+ if (!useJVMTransport() && useSSLTransport())
+ {
+ // need separate container between client and server for SSL.
+ separateContainer.registerFactory(factory);
+ }
+ else
+ {
+ container.registerFactory(factory);
+ }
+ }
+
+ protected IBufferProvider provideBufferProvider(IConnector iConnector)
+ {
+ IBufferProvider bufferProvider = null;
+ if (!useJVMTransport() && useSSLTransport())
+ {
+ // cannot use buffer provider from net4j need to use SSL Buffer inside the SSLConnector.
+ bufferProvider = ((Connector)iConnector).getConfig().getBufferProvider();
+ }
+ else
+ {
+ bufferProvider = Net4jUtil.getBufferProvider(container);
+ }
+
+ return bufferProvider;
+ }
+
+ public void testConnect() throws Exception
+ {
+ startTransport();
+ }
+
+ public void testSendBuffer() throws Exception
+ {
+ startTransport();
+ IConnector iConnecter = getConnector();
+ IChannel channel = iConnecter.openChannel();
+ for (int i = 0; i < 3; i++)
+ {
+ IBuffer buffer = provideBuffer(iConnecter);
+
+ ByteBuffer byteBuffer = buffer.startPutting(channel.getID());
+ byteBuffer.putInt(1970);
+ channel.sendBuffer(buffer);
+ }
+ }
+
+ public void testHandleBuffer() throws Exception
+ {
+ final int COUNT = 3;
+ final CountDownLatch counter = new CountDownLatch(COUNT);
+ container.registerFactory(new TestProtocol.ServerFactory(counter));
+ // need to handle about separating container between client and server for SSL.
+ registerClientFactory(new TestProtocol.ClientFactory());
+ startTransport();
+ IConnector iConnecter = getConnector();
+ IChannel channel = iConnecter.openChannel(TestProtocol.ClientFactory.TYPE, null);
+ for (int i = 0; i < COUNT; i++)
+ {
+ IBuffer buffer = provideBuffer(iConnecter);
+ ByteBuffer byteBuffer = buffer.startPutting(channel.getID());
+ byteBuffer.putInt(1970);
+ channel.sendBuffer(buffer);
+ sleep(50);
+ }
+
+ assertEquals(true, counter.await(2, TimeUnit.SECONDS));
+ }
+
+ public void testStreaming() throws Exception
+ {
+ final int COUNT = 1;
+ final CountDownLatch counter = new CountDownLatch(COUNT);
+ final ChannelInputStream[] inputStream = new ChannelInputStream[1];
+
+ getAcceptor().addListener(new IListener()
+ {
+ public void notifyEvent(IEvent event)
+ {
+ if (event instanceof IContainerEvent<?>)
+ {
+ @SuppressWarnings("unchecked")
+ IContainerEvent<IConnector> e = (IContainerEvent<IConnector>)event;
+ e.getDeltaElement().addListener(new IListener()
+ {
+ public void notifyEvent(IEvent event)
+ {
+ if (event instanceof IContainerEvent<?>)
+ {
+ @SuppressWarnings("unchecked")
+ IContainerEvent<IChannel> e = (IContainerEvent<IChannel>)event;
+ if (e.getDeltaKind() == IContainerDelta.Kind.ADDED)
+ {
+ inputStream[0] = new ChannelInputStream(e.getDeltaElement(), 2000);
+ counter.countDown();
+ }
+ }
+ }
+ });
+ }
+ }
+ });
+
+ IChannel channel = getConnector().openChannel();
+ assertEquals(true, counter.await(2, TimeUnit.SECONDS));
+ assertNotNull(inputStream[0]);
+
+ ChannelOutputStream outputStream = new ChannelOutputStream(channel);
+ outputStream.write(HugeData.getBytes());
+ outputStream.flushWithEOS();
+ outputStream.close();
+
+ try
+ {
+ InputStreamReader isr = new InputStreamReader(inputStream[0]);
+ BufferedReader reader = new BufferedReader(isr);
+ String line;
+ while ((line = reader.readLine()) != null)
+ {
+ msg(line);
+ }
+
+ isr.close();
+ }
+ catch (RuntimeException ex)
+ {
+ IOUtil.print(ex);
+ }
+ }
+
+ /**
+ * TODO Fails occasionally ;-( Caused by: java.lang.IllegalStateException: selectionKey == null
+ */
+ public void testTextStreaming() throws Exception
+ {
+ final int COUNT = 1;
+ final CountDownLatch counter = new CountDownLatch(COUNT);
+ final ChannelInputStream[] inputStream = new ChannelInputStream[1];
+
+ getAcceptor().addListener(new IListener()
+ {
+ public void notifyEvent(IEvent event)
+ {
+ if (event instanceof IContainerEvent<?>)
+ {
+ @SuppressWarnings("unchecked")
+ IContainerEvent<IConnector> e = (IContainerEvent<IConnector>)event;
+ e.getDeltaElement().addListener(new IListener()
+ {
+ public void notifyEvent(IEvent event)
+ {
+ if (event instanceof IContainerEvent<?>)
+ {
+ @SuppressWarnings("unchecked")
+ IContainerEvent<IChannel> e = (IContainerEvent<IChannel>)event;
+ if (e.getDeltaKind() == IContainerDelta.Kind.ADDED)
+ {
+ inputStream[0] = new ChannelInputStream(e.getDeltaElement(), 2000);
+ counter.countDown();
+ }
+ }
+ }
+ });
+ }
+ }
+ });
+
+ IChannel channel = getConnector().openChannel();
+ assertEquals(true, counter.await(2, TimeUnit.SECONDS));
+ assertNotNull(inputStream[0]);
+
+ ChannelOutputStream outputStream = new ChannelOutputStream(channel);
+ PrintStream printer = new PrintStream(outputStream);
+ StringTokenizer tokenizer = HugeData.getTokenizer();
+ while (tokenizer.hasMoreTokens())
+ {
+ String token = tokenizer.nextToken();
+ printer.println(token);
+ }
+
+ outputStream.flushWithEOS();
+ outputStream.close();
+
+ try
+ {
+ InputStreamReader isr = new InputStreamReader(inputStream[0]);
+ BufferedReader reader = new BufferedReader(isr);
+ String line;
+ while ((line = reader.readLine()) != null)
+ {
+ msg(line);
+ }
+
+ isr.close();
+ }
+ catch (RuntimeException ex)
+ {
+ IOUtil.print(ex);
+ }
+ }
+
+ public void testTextStreamingDecoupled() throws Exception
+ {
+ final int COUNT = 1;
+ final CountDownLatch counter = new CountDownLatch(COUNT);
+ final ChannelInputStream[] inputStream = new ChannelInputStream[1];
+
+ getAcceptor().addListener(new IListener()
+ {
+ public void notifyEvent(IEvent event)
+ {
+ if (event instanceof IContainerEvent<?>)
+ {
+ @SuppressWarnings("unchecked")
+ IContainerEvent<IConnector> e = (IContainerEvent<IConnector>)event;
+ e.getDeltaElement().addListener(new IListener()
+ {
+ public void notifyEvent(IEvent event)
+ {
+ if (event instanceof IContainerEvent<?>)
+ {
+ @SuppressWarnings("unchecked")
+ IContainerEvent<IChannel> e = (IContainerEvent<IChannel>)event;
+ if (e.getDeltaKind() == IContainerDelta.Kind.ADDED)
+ {
+ inputStream[0] = new ChannelInputStream(e.getDeltaElement(), 2000);
+ counter.countDown();
+ }
+ }
+ }
+ });
+ }
+ }
+ });
+
+ final IConnector iConnector = getConnector();
+ final IChannel channel = iConnector.openChannel();
+ assertEquals(true, counter.await(2, TimeUnit.SECONDS));
+ assertNotNull(inputStream[0]);
+
+ new Thread()
+ {
+ @Override
+ public void run()
+ {
+ try
+ {
+ IBufferProvider bufferProvider = provideBufferProvider(iConnector);
+ ChannelOutputStream outputStream = new ChannelOutputStream(channel, bufferProvider);
+ PrintStream printer = new PrintStream(outputStream);
+ StringTokenizer tokenizer = HugeData.getTokenizer();
+ while (tokenizer.hasMoreTokens())
+ {
+ String token = tokenizer.nextToken();
+ printer.println(token);
+ }
+
+ outputStream.flushWithEOS();
+ outputStream.close();
+ }
+ catch (IOException ex)
+ {
+ IOUtil.print(ex);
+ fail(ex.getLocalizedMessage());
+ }
+ }
+ }.start();
+
+ try
+ {
+ InputStreamReader isr = new InputStreamReader(inputStream[0]);
+ BufferedReader reader = new BufferedReader(isr);
+ String line;
+ while ((line = reader.readLine()) != null)
+ {
+ msg(line);
+ }
+
+ isr.close();
+ }
+ catch (RuntimeException ex)
+ {
+ IOUtil.print(ex);
+ }
+ }
+
+ public void testDataStreaming() throws Exception
+ {
+ final int COUNT = 1;
+ final CountDownLatch counter = new CountDownLatch(COUNT);
+ final ChannelInputStream[] inputStream = new ChannelInputStream[1];
+
+ getAcceptor().addListener(new IListener()
+ {
+ public void notifyEvent(IEvent event)
+ {
+ if (event instanceof IContainerEvent<?>)
+ {
+ @SuppressWarnings("unchecked")
+ IContainerEvent<IConnector> e = (IContainerEvent<IConnector>)event;
+ e.getDeltaElement().addListener(new IListener()
+ {
+ public void notifyEvent(IEvent event)
+ {
+ if (event instanceof IContainerEvent<?>)
+ {
+ @SuppressWarnings("unchecked")
+ IContainerEvent<IChannel> e = (IContainerEvent<IChannel>)event;
+ if (e.getDeltaKind() == IContainerDelta.Kind.ADDED)
+ {
+ inputStream[0] = new ChannelInputStream(e.getDeltaElement(), 2000);
+ counter.countDown();
+ }
+ }
+ }
+ });
+ }
+ }
+ });
+
+ IChannel channel = getConnector().openChannel();
+ assertEquals(true, counter.await(2, TimeUnit.SECONDS));
+
+ ChannelOutputStream outputStream = new ChannelOutputStream(channel);
+ DataOutputStream dataOutput = new DataOutputStream(outputStream);
+ byte[] data = HugeData.getBytes();
+ dataOutput.writeInt(data.length);
+ dataOutput.write(data);
+ dataOutput.flush();
+ dataOutput.close();
+ outputStream.flush();
+
+ DataInputStream dataInput = new DataInputStream(inputStream[0]);
+ int size = dataInput.readInt();
+ byte[] b = new byte[size];
+ dataInput.read(b);
+ dataInput.close();
+
+ msg(new String(b));
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static final class TestProtocol extends Protocol<CountDownLatch>
+ {
+ public TestProtocol(CountDownLatch counter)
+ {
+ super(ServerFactory.TYPE);
+ setInfraStructure(counter);
+ }
+
+ public void handleBuffer(IBuffer buffer)
+ {
+ IOUtil.OUT().println("BUFFER ARRIVED"); //$NON-NLS-1$
+ buffer.release();
+ getInfraStructure().countDown();
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static class ServerFactory extends ServerProtocolFactory
+ {
+ public static final String TYPE = "test.protocol"; //$NON-NLS-1$
+
+ private CountDownLatch counter;
+
+ public ServerFactory(CountDownLatch counter)
+ {
+ super(TYPE);
+ this.counter = counter;
+ }
+
+ public TestProtocol create(String description) throws ProductCreationException
+ {
+ return new TestProtocol(counter);
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static class ClientFactory extends ClientProtocolFactory
+ {
+ public static final String TYPE = ServerFactory.TYPE;
+
+ public ClientFactory()
+ {
+ super(TYPE);
+ }
+
+ public TestProtocol create(String description) throws ProductCreationException
+ {
+ return new TestProtocol(null);
+ }
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static final class TCP extends TransportTest
+ {
+ @Override
+ protected boolean useJVMTransport()
+ {
+ return false;
+ }
+
+ @Override
+ protected boolean useSSLTransport()
+ {
+ return false;
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static final class JVM extends TransportTest
+ {
+ @Override
+ protected boolean useJVMTransport()
+ {
+ return true;
+ }
+
+ @Override
+ protected boolean useSSLTransport()
+ {
+ return false;
+ }
+ }
+
+ /**
+ * @author Teerawat Chaiyakijpichet (No Magic Asia Ltd.)
+ */
+ public static final class SSL extends TransportTest
+ {
+ @Override
+ protected boolean useJVMTransport()
+ {
+ return false;
+ }
+
+ @Override
+ protected boolean useSSLTransport()
+ {
+ return true;
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/apps/Performance.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/apps/Performance.java
index b22f2ced6a..ef2fe360d1 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/apps/Performance.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/apps/Performance.java
@@ -1,144 +1,144 @@
-/*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- */
-package org.eclipse.net4j.tests.apps;
-
-import org.eclipse.net4j.util.io.IOUtil;
-
-import java.io.IOException;
-import java.net.InetAddress;
-import java.net.InetSocketAddress;
-import java.net.Proxy;
-import java.net.ServerSocket;
-import java.net.Socket;
-import java.net.SocketAddress;
-import java.nio.channels.Selector;
-import java.nio.channels.spi.SelectorProvider;
-import java.util.concurrent.CountDownLatch;
-
-/**
- * @author Eike Stepper
- */
-public class Performance
-{
- public static void main(String[] args) throws Exception
- {
- testInetAddress();
- testServerSocket();
- // testRouter();
- testSocket();
- testSelector();
- }
-
- public static void testInetAddress() throws Exception
- {
- System.out.println(InetAddress.class.getName());
- for (int i = 0; i < 2; i++)
- {
- long start = System.currentTimeMillis();
- InetAddress inet = InetAddress.getByName("localhost"); //$NON-NLS-1$
- inet.getHostAddress();
- long duration = System.currentTimeMillis() - start;
-
- System.out.println(duration);
- }
- }
-
- public static void testServerSocket() throws IOException
- {
- System.out.println(ServerSocket.class.getName());
- for (int i = 0; i < 2; i++)
- {
- long start = System.currentTimeMillis();
- ServerSocket serverSocket = new ServerSocket(2036);
- long duration = System.currentTimeMillis() - start;
-
- System.out.println(duration);
- serverSocket.close();
- }
- }
-
- public static void testRouter() throws Exception
- {
- System.out.println(Socket.class.getName() + " (ROUTER)"); //$NON-NLS-1$
- for (int i = 0; i < 2; i++)
- {
- final SocketAddress endpoint = new InetSocketAddress(InetAddress.getByName("192.168.1.1"), 80); //$NON-NLS-1$
- Socket socket = new Socket(Proxy.NO_PROXY);
-
- long start = System.currentTimeMillis();
- socket.connect(endpoint);
- long duration = System.currentTimeMillis() - start;
-
- System.out.println(duration);
- socket.close();
- Thread.sleep(500);
- }
- }
-
- public static void testSocket() throws Exception
- {
- System.out.println(Socket.class.getName() + " (LOOPBACK)"); //$NON-NLS-1$
- for (int i = 0; i < 2; i++)
- {
- final SocketAddress endpoint = new InetSocketAddress(InetAddress.getByName("127.0.0.1"), 2036); //$NON-NLS-1$
- final CountDownLatch latch = new CountDownLatch(1);
- new Thread()
- {
- @Override
- public void run()
- {
- try
- {
- ServerSocket serverSocket = new ServerSocket();
- serverSocket.bind(endpoint);
- latch.countDown();
-
- Socket socket = serverSocket.accept();
- socket.close();
- serverSocket.close();
- }
- catch (IOException ex)
- {
- IOUtil.print(ex);
- latch.countDown();
- }
- }
- }.start();
-
- latch.await();
- Thread.sleep(500);
- Socket socket = new Socket(Proxy.NO_PROXY);
-
- long start = System.currentTimeMillis();
- socket.connect(endpoint);
- long duration = System.currentTimeMillis() - start;
-
- System.out.println(duration);
- socket.close();
- Thread.sleep(500);
- }
- }
-
- public static void testSelector() throws IOException
- {
- SelectorProvider provider = SelectorProvider.provider();
- System.out.println(provider.getClass().getName());
- for (int i = 0; i < 2; i++)
- {
- long start = System.currentTimeMillis();
- Selector selector = provider.openSelector();
- long duration = System.currentTimeMillis() - start;
-
- System.out.println(duration);
- selector.close();
- }
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.tests.apps;
+
+import org.eclipse.net4j.util.io.IOUtil;
+
+import java.io.IOException;
+import java.net.InetAddress;
+import java.net.InetSocketAddress;
+import java.net.Proxy;
+import java.net.ServerSocket;
+import java.net.Socket;
+import java.net.SocketAddress;
+import java.nio.channels.Selector;
+import java.nio.channels.spi.SelectorProvider;
+import java.util.concurrent.CountDownLatch;
+
+/**
+ * @author Eike Stepper
+ */
+public class Performance
+{
+ public static void main(String[] args) throws Exception
+ {
+ testInetAddress();
+ testServerSocket();
+ // testRouter();
+ testSocket();
+ testSelector();
+ }
+
+ public static void testInetAddress() throws Exception
+ {
+ System.out.println(InetAddress.class.getName());
+ for (int i = 0; i < 2; i++)
+ {
+ long start = System.currentTimeMillis();
+ InetAddress inet = InetAddress.getByName("localhost"); //$NON-NLS-1$
+ inet.getHostAddress();
+ long duration = System.currentTimeMillis() - start;
+
+ System.out.println(duration);
+ }
+ }
+
+ public static void testServerSocket() throws IOException
+ {
+ System.out.println(ServerSocket.class.getName());
+ for (int i = 0; i < 2; i++)
+ {
+ long start = System.currentTimeMillis();
+ ServerSocket serverSocket = new ServerSocket(2036);
+ long duration = System.currentTimeMillis() - start;
+
+ System.out.println(duration);
+ serverSocket.close();
+ }
+ }
+
+ public static void testRouter() throws Exception
+ {
+ System.out.println(Socket.class.getName() + " (ROUTER)"); //$NON-NLS-1$
+ for (int i = 0; i < 2; i++)
+ {
+ final SocketAddress endpoint = new InetSocketAddress(InetAddress.getByName("192.168.1.1"), 80); //$NON-NLS-1$
+ Socket socket = new Socket(Proxy.NO_PROXY);
+
+ long start = System.currentTimeMillis();
+ socket.connect(endpoint);
+ long duration = System.currentTimeMillis() - start;
+
+ System.out.println(duration);
+ socket.close();
+ Thread.sleep(500);
+ }
+ }
+
+ public static void testSocket() throws Exception
+ {
+ System.out.println(Socket.class.getName() + " (LOOPBACK)"); //$NON-NLS-1$
+ for (int i = 0; i < 2; i++)
+ {
+ final SocketAddress endpoint = new InetSocketAddress(InetAddress.getByName("127.0.0.1"), 2036); //$NON-NLS-1$
+ final CountDownLatch latch = new CountDownLatch(1);
+ new Thread()
+ {
+ @Override
+ public void run()
+ {
+ try
+ {
+ ServerSocket serverSocket = new ServerSocket();
+ serverSocket.bind(endpoint);
+ latch.countDown();
+
+ Socket socket = serverSocket.accept();
+ socket.close();
+ serverSocket.close();
+ }
+ catch (IOException ex)
+ {
+ IOUtil.print(ex);
+ latch.countDown();
+ }
+ }
+ }.start();
+
+ latch.await();
+ Thread.sleep(500);
+ Socket socket = new Socket(Proxy.NO_PROXY);
+
+ long start = System.currentTimeMillis();
+ socket.connect(endpoint);
+ long duration = System.currentTimeMillis() - start;
+
+ System.out.println(duration);
+ socket.close();
+ Thread.sleep(500);
+ }
+ }
+
+ public static void testSelector() throws IOException
+ {
+ SelectorProvider provider = SelectorProvider.provider();
+ System.out.println(provider.getClass().getName());
+ for (int i = 0; i < 2; i++)
+ {
+ long start = System.currentTimeMillis();
+ Selector selector = provider.openSelector();
+ long duration = System.currentTimeMillis() - start;
+
+ System.out.println(duration);
+ selector.close();
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/apps/TCPConnectivityLoss.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/apps/TCPConnectivityLoss.java
index efb4206e75..3ce96388e8 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/apps/TCPConnectivityLoss.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/apps/TCPConnectivityLoss.java
@@ -1,102 +1,102 @@
-/*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- */
-package org.eclipse.net4j.tests.apps;
-
-import org.eclipse.net4j.Net4jUtil;
-import org.eclipse.net4j.tcp.ITCPConnector;
-import org.eclipse.net4j.tcp.TCPUtil;
-import org.eclipse.net4j.util.container.ManagedContainer;
-import org.eclipse.net4j.util.lifecycle.ILifecycle;
-import org.eclipse.net4j.util.lifecycle.LifecycleEventAdapter;
-import org.eclipse.net4j.util.om.OMPlatform;
-import org.eclipse.net4j.util.om.log.PrintLogHandler;
-import org.eclipse.net4j.util.om.trace.PrintTraceHandler;
-
-import java.util.Date;
-
-/**
- * @author Eike Stepper
- */
-public class TCPConnectivityLoss
-{
- private static boolean stop;
-
- public static ManagedContainer createContainer()
- {
- OMPlatform.INSTANCE.addLogHandler(PrintLogHandler.CONSOLE);
- OMPlatform.INSTANCE.addTraceHandler(PrintTraceHandler.CONSOLE);
- OMPlatform.INSTANCE.setDebugging(true);
-
- ManagedContainer container = new ManagedContainer();
- Net4jUtil.prepareContainer(container);
- TCPUtil.prepareContainer(container);
- container.activate();
- return container;
- }
-
- public static void sleep() throws Exception
- {
- System.out.println("Started: " + new Date()); //$NON-NLS-1$
- stop = false;
- int count = 0;
- while (System.in.available() == 0)
- {
- Thread.sleep(1000L);
- System.out.print("."); //$NON-NLS-1$
- if (++count % 80 == 0)
- {
- System.out.println();
- }
-
- if (stop)
- {
- System.out.println("Loss of connectivity: " + new Date()); //$NON-NLS-1$
- }
- }
- }
-
- /**
- * @author Eike Stepper
- */
- public static class Server
- {
- public static void main(String[] args) throws Exception
- {
- ManagedContainer container = createContainer();
- TCPUtil.getAcceptor(container, null);
- sleep();
- container.deactivate();
- }
- }
-
- /**
- * @author Eike Stepper
- */
- public static class Client
- {
- public static void main(String[] args) throws Exception
- {
- ManagedContainer container = createContainer();
- ITCPConnector connector = TCPUtil.getConnector(container, "192.168.1.35"); //$NON-NLS-1$
- connector.addListener(new LifecycleEventAdapter()
- {
- @Override
- protected void onDeactivated(ILifecycle lifecycle)
- {
- stop = true;
- }
- });
-
- sleep();
- container.deactivate();
- }
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.tests.apps;
+
+import org.eclipse.net4j.Net4jUtil;
+import org.eclipse.net4j.tcp.ITCPConnector;
+import org.eclipse.net4j.tcp.TCPUtil;
+import org.eclipse.net4j.util.container.ManagedContainer;
+import org.eclipse.net4j.util.lifecycle.ILifecycle;
+import org.eclipse.net4j.util.lifecycle.LifecycleEventAdapter;
+import org.eclipse.net4j.util.om.OMPlatform;
+import org.eclipse.net4j.util.om.log.PrintLogHandler;
+import org.eclipse.net4j.util.om.trace.PrintTraceHandler;
+
+import java.util.Date;
+
+/**
+ * @author Eike Stepper
+ */
+public class TCPConnectivityLoss
+{
+ private static boolean stop;
+
+ public static ManagedContainer createContainer()
+ {
+ OMPlatform.INSTANCE.addLogHandler(PrintLogHandler.CONSOLE);
+ OMPlatform.INSTANCE.addTraceHandler(PrintTraceHandler.CONSOLE);
+ OMPlatform.INSTANCE.setDebugging(true);
+
+ ManagedContainer container = new ManagedContainer();
+ Net4jUtil.prepareContainer(container);
+ TCPUtil.prepareContainer(container);
+ container.activate();
+ return container;
+ }
+
+ public static void sleep() throws Exception
+ {
+ System.out.println("Started: " + new Date()); //$NON-NLS-1$
+ stop = false;
+ int count = 0;
+ while (System.in.available() == 0)
+ {
+ Thread.sleep(1000L);
+ System.out.print("."); //$NON-NLS-1$
+ if (++count % 80 == 0)
+ {
+ System.out.println();
+ }
+
+ if (stop)
+ {
+ System.out.println("Loss of connectivity: " + new Date()); //$NON-NLS-1$
+ }
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static class Server
+ {
+ public static void main(String[] args) throws Exception
+ {
+ ManagedContainer container = createContainer();
+ TCPUtil.getAcceptor(container, null);
+ sleep();
+ container.deactivate();
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static class Client
+ {
+ public static void main(String[] args) throws Exception
+ {
+ ManagedContainer container = createContainer();
+ ITCPConnector connector = TCPUtil.getConnector(container, "192.168.1.35"); //$NON-NLS-1$
+ connector.addListener(new LifecycleEventAdapter()
+ {
+ @Override
+ protected void onDeactivated(ILifecycle lifecycle)
+ {
+ stop = true;
+ }
+ });
+
+ sleep();
+ container.deactivate();
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/bugzilla/Bugzilla_241463_Test.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/bugzilla/Bugzilla_241463_Test.java
index 9bb5d6d80b..d44fc80fab 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/bugzilla/Bugzilla_241463_Test.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/bugzilla/Bugzilla_241463_Test.java
@@ -1,212 +1,212 @@
-/*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- * Teerawat Chaiyakijpichet (No Magic Asia Ltd.) - maintenance (SSL)
- */
-package org.eclipse.net4j.tests.bugzilla;
-
-import org.eclipse.net4j.TransportInjector;
-import org.eclipse.net4j.internal.tcp.TCPAcceptor;
-import org.eclipse.net4j.internal.tcp.TCPAcceptorFactory;
-import org.eclipse.net4j.internal.tcp.TCPConnectorFactory;
-import org.eclipse.net4j.internal.tcp.TCPSelectorFactory;
-import org.eclipse.net4j.internal.tcp.TCPSelectorInjector;
-import org.eclipse.net4j.internal.tcp.TCPServerConnector;
-import org.eclipse.net4j.internal.tcp.ssl.SSLAcceptor;
-import org.eclipse.net4j.internal.tcp.ssl.SSLAcceptorFactory;
-import org.eclipse.net4j.internal.tcp.ssl.SSLConnectorFactory;
-import org.eclipse.net4j.internal.tcp.ssl.SSLServerConnector;
-import org.eclipse.net4j.tcp.ITCPAcceptor;
-import org.eclipse.net4j.tcp.ITCPSelector;
-import org.eclipse.net4j.tests.AbstractTransportTest;
-import org.eclipse.net4j.tests.ChannelTest;
-import org.eclipse.net4j.tests.signal.TestSignalProtocol;
-import org.eclipse.net4j.util.concurrent.ExecutorServiceFactory;
-import org.eclipse.net4j.util.container.IManagedContainer;
-import org.eclipse.net4j.util.container.ManagedContainer;
-import org.eclipse.net4j.util.security.RandomizerFactory;
-
-import org.eclipse.internal.net4j.buffer.BufferProviderFactory;
-
-import org.eclipse.spi.net4j.InternalChannel;
-
-import java.nio.channels.ClosedChannelException;
-import java.nio.channels.ServerSocketChannel;
-import java.nio.channels.SocketChannel;
-
-/**
- * @author Eike Stepper
- */
-public class Bugzilla_241463_Test extends AbstractTransportTest
-{
- @Override
- protected IManagedContainer createContainer()
- {
- IManagedContainer container = new ManagedContainer();
-
- // Net4j
- container.registerFactory(new ExecutorServiceFactory());
- container.registerFactory(new BufferProviderFactory());
- container.registerFactory(new RandomizerFactory());
- container.addPostProcessor(new TransportInjector());
-
- container.registerFactory(new TCPSelectorFactory());
- container.addPostProcessor(new TCPSelectorInjector());
-
- if (useSSLTransport())
- {
- // SSL
- container.registerFactory(new FakeSSLAcceptorFactory());
- container.registerFactory(new SSLConnectorFactory());
- }
- else
- {
- // TCP
- container.registerFactory(new FakeAcceptorFactory());
- container.registerFactory(new TCPConnectorFactory());
- }
-
- // Test
- container.registerFactory(new TestSignalProtocol.Factory());
- return container;
- }
-
- public void testBugzilla241463() throws Exception
- {
- startTransport();
- getConnector().setOpenChannelTimeout(2000L);
-
- try
- {
- new TestSignalProtocol(getConnector());
- fail("Exception expected"); //$NON-NLS-1$
- }
- catch (Exception expected)
- {
- }
- }
-
- /**
- * @author Eike Stepper
- */
- private static final class FakeAcceptorFactory extends TCPAcceptorFactory
- {
- @Override
- public TCPAcceptor create(String description)
- {
- TCPAcceptor acceptor = new TCPAcceptor()
- {
- @Override
- protected TCPServerConnector createConnector()
- {
- return new TCPServerConnector(this)
- {
- @Override
- public InternalChannel inverseOpenChannel(short channelIndex, String protocolID)
- {
- throw new RuntimeException("Simulated problem"); //$NON-NLS-1$
- }
- };
- }
- };
-
- acceptor.setAddress(ITCPAcceptor.DEFAULT_ADDRESS);
- acceptor.setPort(ITCPAcceptor.DEFAULT_PORT);
- return acceptor;
- }
- }
-
- /**
- * @author Eike Stepper
- */
- private static final class FakeSSLAcceptorFactory extends SSLAcceptorFactory
- {
- @Override
- public SSLAcceptor create(String description)
- {
- SSLAcceptor acceptor = new SSLAcceptor()
- {
-
- @Override
- public void handleAccept(ITCPSelector selector, ServerSocketChannel serverSocketChannel)
- {
- try
- {
- SocketChannel socketChannel = serverSocketChannel.accept();
- if (socketChannel != null)
- {
- socketChannel.configureBlocking(false);
-
- SSLServerConnector connector = new SSLServerConnector(this)
- {
- @Override
- public InternalChannel inverseOpenChannel(short channelID, String protocolID)
- {
- throw new RuntimeException("Simulated problem"); //$NON-NLS-1$
- }
- };
- prepareConnector(connector);
- connector.setSocketChannel(socketChannel);
- connector.setSelector(selector);
- connector.activate();
- }
- }
- catch (ClosedChannelException ex)
- {
- deactivateAsync();
- }
- catch (Exception ex)
- {
- deactivateAsync();
- }
- }
- };
-
- acceptor.setAddress(ITCPAcceptor.DEFAULT_ADDRESS);
- acceptor.setPort(ITCPAcceptor.DEFAULT_PORT);
- return acceptor;
- }
- }
-
- /**
- * @author Eike Stepper
- */
- public static final class TCP extends ChannelTest
- {
- @Override
- protected boolean useJVMTransport()
- {
- return false;
- }
-
- @Override
- protected boolean useSSLTransport()
- {
- return false;
- }
- }
-
- /**
- * @author Teerawat Chaiyakijpichet (No Magic Asia Ltd.)
- */
- public static final class SSL extends ChannelTest
- {
- @Override
- protected boolean useJVMTransport()
- {
- return false;
- }
-
- @Override
- protected boolean useSSLTransport()
- {
- return true;
- }
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ * Teerawat Chaiyakijpichet (No Magic Asia Ltd.) - maintenance (SSL)
+ */
+package org.eclipse.net4j.tests.bugzilla;
+
+import org.eclipse.net4j.TransportInjector;
+import org.eclipse.net4j.internal.tcp.TCPAcceptor;
+import org.eclipse.net4j.internal.tcp.TCPAcceptorFactory;
+import org.eclipse.net4j.internal.tcp.TCPConnectorFactory;
+import org.eclipse.net4j.internal.tcp.TCPSelectorFactory;
+import org.eclipse.net4j.internal.tcp.TCPSelectorInjector;
+import org.eclipse.net4j.internal.tcp.TCPServerConnector;
+import org.eclipse.net4j.internal.tcp.ssl.SSLAcceptor;
+import org.eclipse.net4j.internal.tcp.ssl.SSLAcceptorFactory;
+import org.eclipse.net4j.internal.tcp.ssl.SSLConnectorFactory;
+import org.eclipse.net4j.internal.tcp.ssl.SSLServerConnector;
+import org.eclipse.net4j.tcp.ITCPAcceptor;
+import org.eclipse.net4j.tcp.ITCPSelector;
+import org.eclipse.net4j.tests.AbstractTransportTest;
+import org.eclipse.net4j.tests.ChannelTest;
+import org.eclipse.net4j.tests.signal.TestSignalProtocol;
+import org.eclipse.net4j.util.concurrent.ExecutorServiceFactory;
+import org.eclipse.net4j.util.container.IManagedContainer;
+import org.eclipse.net4j.util.container.ManagedContainer;
+import org.eclipse.net4j.util.security.RandomizerFactory;
+
+import org.eclipse.internal.net4j.buffer.BufferProviderFactory;
+
+import org.eclipse.spi.net4j.InternalChannel;
+
+import java.nio.channels.ClosedChannelException;
+import java.nio.channels.ServerSocketChannel;
+import java.nio.channels.SocketChannel;
+
+/**
+ * @author Eike Stepper
+ */
+public class Bugzilla_241463_Test extends AbstractTransportTest
+{
+ @Override
+ protected IManagedContainer createContainer()
+ {
+ IManagedContainer container = new ManagedContainer();
+
+ // Net4j
+ container.registerFactory(new ExecutorServiceFactory());
+ container.registerFactory(new BufferProviderFactory());
+ container.registerFactory(new RandomizerFactory());
+ container.addPostProcessor(new TransportInjector());
+
+ container.registerFactory(new TCPSelectorFactory());
+ container.addPostProcessor(new TCPSelectorInjector());
+
+ if (useSSLTransport())
+ {
+ // SSL
+ container.registerFactory(new FakeSSLAcceptorFactory());
+ container.registerFactory(new SSLConnectorFactory());
+ }
+ else
+ {
+ // TCP
+ container.registerFactory(new FakeAcceptorFactory());
+ container.registerFactory(new TCPConnectorFactory());
+ }
+
+ // Test
+ container.registerFactory(new TestSignalProtocol.Factory());
+ return container;
+ }
+
+ public void testBugzilla241463() throws Exception
+ {
+ startTransport();
+ getConnector().setOpenChannelTimeout(2000L);
+
+ try
+ {
+ new TestSignalProtocol(getConnector());
+ fail("Exception expected"); //$NON-NLS-1$
+ }
+ catch (Exception expected)
+ {
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ private static final class FakeAcceptorFactory extends TCPAcceptorFactory
+ {
+ @Override
+ public TCPAcceptor create(String description)
+ {
+ TCPAcceptor acceptor = new TCPAcceptor()
+ {
+ @Override
+ protected TCPServerConnector createConnector()
+ {
+ return new TCPServerConnector(this)
+ {
+ @Override
+ public InternalChannel inverseOpenChannel(short channelIndex, String protocolID)
+ {
+ throw new RuntimeException("Simulated problem"); //$NON-NLS-1$
+ }
+ };
+ }
+ };
+
+ acceptor.setAddress(ITCPAcceptor.DEFAULT_ADDRESS);
+ acceptor.setPort(ITCPAcceptor.DEFAULT_PORT);
+ return acceptor;
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ private static final class FakeSSLAcceptorFactory extends SSLAcceptorFactory
+ {
+ @Override
+ public SSLAcceptor create(String description)
+ {
+ SSLAcceptor acceptor = new SSLAcceptor()
+ {
+
+ @Override
+ public void handleAccept(ITCPSelector selector, ServerSocketChannel serverSocketChannel)
+ {
+ try
+ {
+ SocketChannel socketChannel = serverSocketChannel.accept();
+ if (socketChannel != null)
+ {
+ socketChannel.configureBlocking(false);
+
+ SSLServerConnector connector = new SSLServerConnector(this)
+ {
+ @Override
+ public InternalChannel inverseOpenChannel(short channelID, String protocolID)
+ {
+ throw new RuntimeException("Simulated problem"); //$NON-NLS-1$
+ }
+ };
+ prepareConnector(connector);
+ connector.setSocketChannel(socketChannel);
+ connector.setSelector(selector);
+ connector.activate();
+ }
+ }
+ catch (ClosedChannelException ex)
+ {
+ deactivateAsync();
+ }
+ catch (Exception ex)
+ {
+ deactivateAsync();
+ }
+ }
+ };
+
+ acceptor.setAddress(ITCPAcceptor.DEFAULT_ADDRESS);
+ acceptor.setPort(ITCPAcceptor.DEFAULT_PORT);
+ return acceptor;
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static final class TCP extends ChannelTest
+ {
+ @Override
+ protected boolean useJVMTransport()
+ {
+ return false;
+ }
+
+ @Override
+ protected boolean useSSLTransport()
+ {
+ return false;
+ }
+ }
+
+ /**
+ * @author Teerawat Chaiyakijpichet (No Magic Asia Ltd.)
+ */
+ public static final class SSL extends ChannelTest
+ {
+ @Override
+ protected boolean useJVMTransport()
+ {
+ return false;
+ }
+
+ @Override
+ protected boolean useSSLTransport()
+ {
+ return true;
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/bugzilla/Bugzilla_262875_Test.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/bugzilla/Bugzilla_262875_Test.java
index 79cb381779..0bc708cf10 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/bugzilla/Bugzilla_262875_Test.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/bugzilla/Bugzilla_262875_Test.java
@@ -1,210 +1,210 @@
-/*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * David Bonneau - initial API and implementation
- * Andre Dietisheim - maintenance
- */
-package org.eclipse.net4j.tests.bugzilla;
-
-import org.eclipse.net4j.Net4jUtil;
-import org.eclipse.net4j.connector.IConnector;
-import org.eclipse.net4j.jvm.JVMUtil;
-import org.eclipse.net4j.signal.IndicationWithResponse;
-import org.eclipse.net4j.signal.RequestWithConfirmation;
-import org.eclipse.net4j.signal.SignalProtocol;
-import org.eclipse.net4j.signal.SignalReactor;
-import org.eclipse.net4j.util.IErrorHandler;
-import org.eclipse.net4j.util.concurrent.Worker;
-import org.eclipse.net4j.util.container.ContainerUtil;
-import org.eclipse.net4j.util.container.IManagedContainer;
-import org.eclipse.net4j.util.factory.ProductCreationException;
-import org.eclipse.net4j.util.io.ExtendedDataInputStream;
-import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
-import org.eclipse.net4j.util.tests.AbstractOMTest;
-
-import org.eclipse.spi.net4j.ServerProtocolFactory;
-
-import java.nio.BufferUnderflowException;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicBoolean;
-
-/**
- * @author David Bonneau
- */
-public class Bugzilla_262875_Test extends AbstractOMTest
-{
- /** the length of the metadata sent in a buffer: channelID, correlationID */
- private static final short BUFFER_METADATA_LENTGH = 10;
-
- private IManagedContainer container;
-
- private IConnector connector;
-
- @Override
- protected void doSetUp() throws Exception
- {
- super.doSetUp();
- container = ContainerUtil.createContainer();
- Net4jUtil.prepareContainer(container);
- JVMUtil.prepareContainer(container);
- container.registerFactory(new TestProtocol.Factory());
- container.activate();
-
- JVMUtil.getAcceptor(container, "default");
- connector = JVMUtil.getConnector(container, "default");
- }
-
- @Override
- protected void doTearDown() throws Exception
- {
- connector.close();
- container.deactivate();
- super.doTearDown();
- }
-
- /**
- * Tests if a buffer underflow exception occurs if the data sent in a request exactly matches the capacity of a
- * buffer.
- *
- * @throws Exception
- * the exception
- */
- public void testGivenDataMatchesBufferLengthThenBufferUnderflowException() throws Exception
- {
- final AtomicBoolean failed = new AtomicBoolean(false);
- final CountDownLatch latch = new CountDownLatch(1);
- IErrorHandler oldErrorHandler = Worker.setGlobalErrorHandler(new IErrorHandler()
- {
- public void handleError(Throwable t)
- {
- t.printStackTrace();
- if (t instanceof BufferUnderflowException)
- {
- failed.set(true);
- }
-
- latch.countDown();
- }
- });
-
- try
- {
- TestProtocol protocol = new TestProtocol();
- protocol.open(connector);
-
- short bufferCapacity = protocol.getBufferProvider().getBufferCapacity();
- new TestProtocol.Request(protocol, bufferCapacity - BUFFER_METADATA_LENTGH).send();
-
- latch.await(DEFAULT_TIMEOUT_EXPECTED, TimeUnit.MILLISECONDS);
- assertEquals(false, failed.get());
- }
- finally
- {
- Worker.setGlobalErrorHandler(oldErrorHandler);
- }
- }
-
- /**
- * @author David Bonneau
- */
- private static final class TestProtocol extends SignalProtocol<Object>
- {
- private static final String NAME = "TEST_PROTOCOL";
-
- private static final short SIGNAL_ID = 10;
-
- public TestProtocol()
- {
- super(NAME);
- }
-
- @Override
- protected SignalReactor createSignalReactor(short signalID)
- {
- switch (signalID)
- {
- case SIGNAL_ID:
- return new Indication(this);
- }
-
- return super.createSignalReactor(signalID);
- }
-
- /**
- * @author David Bonneau
- */
- private static final class Request extends RequestWithConfirmation<Boolean>
- {
- private int requestNumOfBytes;
-
- public Request(SignalProtocol<?> protocol, int requestNumOfBytes)
- {
- super(protocol, SIGNAL_ID);
- this.requestNumOfBytes = requestNumOfBytes;
- }
-
- @Override
- protected void requesting(ExtendedDataOutputStream out) throws Exception
- {
- for (int i = 0; i < requestNumOfBytes; ++i)
- {
- out.writeByte(i);
- }
-
- // delay completion
- Thread.sleep(100);
- }
-
- @Override
- protected Boolean confirming(ExtendedDataInputStream in) throws Exception
- {
- return in.readBoolean();
- }
- }
-
- /**
- * @author David Bonneau
- */
- private static final class Indication extends IndicationWithResponse
- {
- public Indication(SignalProtocol<?> protocol)
- {
- super(protocol, SIGNAL_ID);
- }
-
- @Override
- protected void indicating(ExtendedDataInputStream in) throws Exception
- {
- System.out.println("indicating");
- }
-
- @Override
- protected void responding(ExtendedDataOutputStream out) throws Exception
- {
- out.writeBoolean(true);
- }
- }
-
- /**
- * @author David Bonneau
- */
- private static final class Factory extends ServerProtocolFactory
- {
- public Factory()
- {
- super(NAME);
- }
-
- public Object create(String description) throws ProductCreationException
- {
- return new TestProtocol();
- }
- }
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * David Bonneau - initial API and implementation
+ * Andre Dietisheim - maintenance
+ */
+package org.eclipse.net4j.tests.bugzilla;
+
+import org.eclipse.net4j.Net4jUtil;
+import org.eclipse.net4j.connector.IConnector;
+import org.eclipse.net4j.jvm.JVMUtil;
+import org.eclipse.net4j.signal.IndicationWithResponse;
+import org.eclipse.net4j.signal.RequestWithConfirmation;
+import org.eclipse.net4j.signal.SignalProtocol;
+import org.eclipse.net4j.signal.SignalReactor;
+import org.eclipse.net4j.util.IErrorHandler;
+import org.eclipse.net4j.util.concurrent.Worker;
+import org.eclipse.net4j.util.container.ContainerUtil;
+import org.eclipse.net4j.util.container.IManagedContainer;
+import org.eclipse.net4j.util.factory.ProductCreationException;
+import org.eclipse.net4j.util.io.ExtendedDataInputStream;
+import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
+import org.eclipse.net4j.util.tests.AbstractOMTest;
+
+import org.eclipse.spi.net4j.ServerProtocolFactory;
+
+import java.nio.BufferUnderflowException;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+/**
+ * @author David Bonneau
+ */
+public class Bugzilla_262875_Test extends AbstractOMTest
+{
+ /** the length of the metadata sent in a buffer: channelID, correlationID */
+ private static final short BUFFER_METADATA_LENTGH = 10;
+
+ private IManagedContainer container;
+
+ private IConnector connector;
+
+ @Override
+ protected void doSetUp() throws Exception
+ {
+ super.doSetUp();
+ container = ContainerUtil.createContainer();
+ Net4jUtil.prepareContainer(container);
+ JVMUtil.prepareContainer(container);
+ container.registerFactory(new TestProtocol.Factory());
+ container.activate();
+
+ JVMUtil.getAcceptor(container, "default");
+ connector = JVMUtil.getConnector(container, "default");
+ }
+
+ @Override
+ protected void doTearDown() throws Exception
+ {
+ connector.close();
+ container.deactivate();
+ super.doTearDown();
+ }
+
+ /**
+ * Tests if a buffer underflow exception occurs if the data sent in a request exactly matches the capacity of a
+ * buffer.
+ *
+ * @throws Exception
+ * the exception
+ */
+ public void testGivenDataMatchesBufferLengthThenBufferUnderflowException() throws Exception
+ {
+ final AtomicBoolean failed = new AtomicBoolean(false);
+ final CountDownLatch latch = new CountDownLatch(1);
+ IErrorHandler oldErrorHandler = Worker.setGlobalErrorHandler(new IErrorHandler()
+ {
+ public void handleError(Throwable t)
+ {
+ t.printStackTrace();
+ if (t instanceof BufferUnderflowException)
+ {
+ failed.set(true);
+ }
+
+ latch.countDown();
+ }
+ });
+
+ try
+ {
+ TestProtocol protocol = new TestProtocol();
+ protocol.open(connector);
+
+ short bufferCapacity = protocol.getBufferProvider().getBufferCapacity();
+ new TestProtocol.Request(protocol, bufferCapacity - BUFFER_METADATA_LENTGH).send();
+
+ latch.await(DEFAULT_TIMEOUT_EXPECTED, TimeUnit.MILLISECONDS);
+ assertEquals(false, failed.get());
+ }
+ finally
+ {
+ Worker.setGlobalErrorHandler(oldErrorHandler);
+ }
+ }
+
+ /**
+ * @author David Bonneau
+ */
+ private static final class TestProtocol extends SignalProtocol<Object>
+ {
+ private static final String NAME = "TEST_PROTOCOL";
+
+ private static final short SIGNAL_ID = 10;
+
+ public TestProtocol()
+ {
+ super(NAME);
+ }
+
+ @Override
+ protected SignalReactor createSignalReactor(short signalID)
+ {
+ switch (signalID)
+ {
+ case SIGNAL_ID:
+ return new Indication(this);
+ }
+
+ return super.createSignalReactor(signalID);
+ }
+
+ /**
+ * @author David Bonneau
+ */
+ private static final class Request extends RequestWithConfirmation<Boolean>
+ {
+ private int requestNumOfBytes;
+
+ public Request(SignalProtocol<?> protocol, int requestNumOfBytes)
+ {
+ super(protocol, SIGNAL_ID);
+ this.requestNumOfBytes = requestNumOfBytes;
+ }
+
+ @Override
+ protected void requesting(ExtendedDataOutputStream out) throws Exception
+ {
+ for (int i = 0; i < requestNumOfBytes; ++i)
+ {
+ out.writeByte(i);
+ }
+
+ // delay completion
+ Thread.sleep(100);
+ }
+
+ @Override
+ protected Boolean confirming(ExtendedDataInputStream in) throws Exception
+ {
+ return in.readBoolean();
+ }
+ }
+
+ /**
+ * @author David Bonneau
+ */
+ private static final class Indication extends IndicationWithResponse
+ {
+ public Indication(SignalProtocol<?> protocol)
+ {
+ super(protocol, SIGNAL_ID);
+ }
+
+ @Override
+ protected void indicating(ExtendedDataInputStream in) throws Exception
+ {
+ System.out.println("indicating");
+ }
+
+ @Override
+ protected void responding(ExtendedDataOutputStream out) throws Exception
+ {
+ out.writeBoolean(true);
+ }
+ }
+
+ /**
+ * @author David Bonneau
+ */
+ private static final class Factory extends ServerProtocolFactory
+ {
+ public Factory()
+ {
+ super(NAME);
+ }
+
+ public Object create(String description) throws ProductCreationException
+ {
+ return new TestProtocol();
+ }
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/bundle/OM.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/bundle/OM.java
index 72ed86ab45..49794b3590 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/bundle/OM.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/bundle/OM.java
@@ -1,44 +1,44 @@
-/*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- */
-package org.eclipse.net4j.tests.bundle;
-
-import org.eclipse.net4j.util.om.OMBundle;
-import org.eclipse.net4j.util.om.OMPlatform;
-import org.eclipse.net4j.util.om.OSGiActivator;
-import org.eclipse.net4j.util.om.log.OMLogger;
-import org.eclipse.net4j.util.om.trace.OMTracer;
-
-/**
- * The <em>Operations & Maintenance</em> class of this bundle.
- *
- * @author Eike Stepper
- */
-public abstract class OM
-{
- public static final String BUNDLE_ID = "org.eclipse.net4j.tests"; //$NON-NLS-1$
-
- public static final OMBundle BUNDLE = OMPlatform.INSTANCE.bundle(BUNDLE_ID, OM.class);
-
- public static final OMTracer DEBUG = BUNDLE.tracer("debug"); //$NON-NLS-1$
-
- public static final OMLogger LOG = BUNDLE.logger();
-
- /**
- * @author Eike Stepper
- */
- public static final class Activator extends OSGiActivator
- {
- public Activator()
- {
- super(BUNDLE);
- }
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.tests.bundle;
+
+import org.eclipse.net4j.util.om.OMBundle;
+import org.eclipse.net4j.util.om.OMPlatform;
+import org.eclipse.net4j.util.om.OSGiActivator;
+import org.eclipse.net4j.util.om.log.OMLogger;
+import org.eclipse.net4j.util.om.trace.OMTracer;
+
+/**
+ * The <em>Operations & Maintenance</em> class of this bundle.
+ *
+ * @author Eike Stepper
+ */
+public abstract class OM
+{
+ public static final String BUNDLE_ID = "org.eclipse.net4j.tests"; //$NON-NLS-1$
+
+ public static final OMBundle BUNDLE = OMPlatform.INSTANCE.bundle(BUNDLE_ID, OM.class);
+
+ public static final OMTracer DEBUG = BUNDLE.tracer("debug"); //$NON-NLS-1$
+
+ public static final OMLogger LOG = BUNDLE.logger();
+
+ /**
+ * @author Eike Stepper
+ */
+ public static final class Activator extends OSGiActivator
+ {
+ public Activator()
+ {
+ super(BUNDLE);
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/data/HugeData.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/data/HugeData.java
index ea0fc9ffaf..4331c19988 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/data/HugeData.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/data/HugeData.java
@@ -1,245 +1,245 @@
-/*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- */
-package org.eclipse.net4j.tests.data;
-
-import java.util.StringTokenizer;
-
-/**
- * @author Eike Stepper
- */
-public final class HugeData
-{
- public static final String NL = System.getProperty("line.separator"); //$NON-NLS-1$
-
- public static StringTokenizer getTokenizer()
- {
- return new StringTokenizer(getText(), NL);
- }
-
- public static String[] getArray()
- {
- return getText().split(NL);
- }
-
- public static byte[] getBytes()
- {
- return getText().getBytes();
- }
-
- public static String getText()
- {
- return "/**" + NL //$NON-NLS-1$
- + " * COPYRIGHT (C) 2004 - 2008 EIKE STEPPER, GERMANY." + NL //$NON-NLS-1$
- + " * ALL RIGHTS RESERVED. THIS PROGRAM AND THE ACCOMPANYING MATERIALS" + NL //$NON-NLS-1$
- + " * ARE MADE AVAILABLE UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE V1.0" + NL //$NON-NLS-1$
- + " * WHICH ACCOMPANIES THIS DISTRIBUTION, AND IS AVAILABLE AT" + NL //$NON-NLS-1$
- + " * HTTP://WWW.ECLIPSE.ORG/LEGAL/EPL-V10.HTML" + NL + " * " + NL + " * CONTRIBUTORS:" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- + " * EIKE STEPPER - INITIAL API AND IMPLEMENTATION" + NL //$NON-NLS-1$
- + " */" + NL //$NON-NLS-1$
- + "PACKAGE ORG.ECLIPSE.INTERNAL.NET4J.TRANSPORT.CONNECTOR;" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$
- + "IMPORT ORG.ECLIPSE.NET4J.TRANSPORT.BUFFER.BUFFERPROVIDER;" + NL //$NON-NLS-1$
- + "IMPORT ORG.ECLIPSE.NET4J.TRANSPORT.CHANNEL.CHANNEL;" + NL //$NON-NLS-1$
- + "IMPORT ORG.ECLIPSE.NET4J.TRANSPORT.CHANNEL.MULTIPLEXER;" + NL //$NON-NLS-1$
- + "IMPORT ORG.ECLIPSE.NET4J.TRANSPORT.CONNECTOR.CONNECTOR;" + NL //$NON-NLS-1$
- + "IMPORT ORG.ECLIPSE.NET4J.TRANSPORT.CONNECTOR.CONNECTOREXCEPTION;" + NL //$NON-NLS-1$
- + "IMPORT ORG.ECLIPSE.NET4J.TRANSPORT.CONNECTOR.CREDENTIALS;" + NL //$NON-NLS-1$
- + "IMPORT ORG.ECLIPSE.NET4J.TRANSPORT.CONNECTOR.PROTOCOL;" + NL //$NON-NLS-1$
- + "IMPORT ORG.ECLIPSE.NET4J.TRANSPORT.CONNECTOR.PROTOCOLFACTORY;" + NL //$NON-NLS-1$
- + "IMPORT ORG.ECLIPSE.NET4J.UTIL.LIFECYCLE.LIFECYCLELISTENER;" + NL //$NON-NLS-1$
- + "IMPORT ORG.ECLIPSE.NET4J.UTIL.LIFECYCLE.LIFECYCLENOTIFIER;" + NL //$NON-NLS-1$
- + "IMPORT ORG.ECLIPSE.NET4J.UTIL.REGISTRY.IREGISTRY;" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$
- + "IMPORT ORG.ECLIPSE.INTERNAL.NET4J.TRANSPORT.CHANNEL.CHANNELIMPL;" + NL //$NON-NLS-1$
- + "IMPORT ORG.ECLIPSE.INTERNAL.NET4J.UTIL.STREAM.BUFFERQUEUE;" + NL //$NON-NLS-1$
- + "IMPORT ORG.ECLIPSE.INTERNAL.NET4J.UTIL.LIFECYCLE.ABSTRACTCOMPONENT;" + NL //$NON-NLS-1$
- + "IMPORT ORG.ECLIPSE.INTERNAL.NET4J.UTIL.LIFECYCLE.LIFECYCLEUTIL;" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$
- + "IMPORT JAVA.UTIL.ARRAYLIST;" + NL + "IMPORT JAVA.UTIL.LIST;" + NL + "IMPORT JAVA.UTIL.QUEUE;" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- + "IMPORT JAVA.UTIL.CONCURRENT.CONCURRENTLINKEDQUEUE;" + NL + "IMPORT JAVA.UTIL.CONCURRENT.COUNTDOWNLATCH;" //$NON-NLS-1$ //$NON-NLS-2$
- + NL + "IMPORT JAVA.UTIL.CONCURRENT.EXECUTORSERVICE;" + NL + "IMPORT JAVA.UTIL.CONCURRENT.TIMEUNIT;" + NL + "" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- + NL + "/**" + NL + " * @AUTHOR EIKE STEPPER" + NL + " */" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- + "PUBLIC ABSTRACT CLASS ABSTRACTCONNECTOR EXTENDS ABSTRACTLIFECYCLE IMPLEMENTS CONNECTOR, CHANNELMULTIPLEXER" //$NON-NLS-1$
- + NL + "{" + NL + " PRIVATE STATIC FINAL CHANNELIMPL NULL_CHANNEL = NEW CHANNELIMPL(NULL);" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- + " PRIVATE CONNECTORCREDENTIALS CREDENTIALS;" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$
- + " PRIVATE IREGISTRY<STRING, PROTOCOLFACTORY> PROTOCOLFACTORYREGISTRY;" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$
- + " PRIVATE BUFFERPROVIDER BUFFERPROVIDER;" + NL + "" + NL + " /**" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- + " * AN OPTIONAL EXECUTOR TO BE USED BY THE {@LINK CHANNEL}S TO PROCESS THEIR" + NL //$NON-NLS-1$
- + " * {@LINK CHANNELIMPL#RECEIVEQUEUE} INSTEAD OF THE CURRENT THREAD. IF NOT" + NL //$NON-NLS-1$
- + " * <CODE>NULL</CODE> THE SENDER AND THE RECEIVER PEERS BECOME DECOUPLED." + NL + " * <P>" + NL + " */" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- + NL + " PRIVATE EXECUTORSERVICE RECEIVEEXECUTOR;" + NL + "" + NL + " /**" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- + " * TODO SYNCHRONIZE ON CHANNELS?" + NL + " */" + NL //$NON-NLS-1$ //$NON-NLS-2$
- + " PRIVATE LIST<CHANNELIMPL> CHANNELS = NEW ARRAYLIST();" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$
- + " PRIVATE STATE STATE = STATE.DISCONNECTED;" + NL + "" + NL + " /**" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- + " * DON\'T INITIALIZE LAZILY TO CIRCUMVENT SYNCHRONIZATION!" + NL + " */" + NL //$NON-NLS-1$ //$NON-NLS-2$
- + " PRIVATE QUEUE<STATELISTENER> STATELISTENERS = NEW CONCURRENTLINKEDQUEUE();" + NL + "" + NL + " /**" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- + " * DON\'T INITIALIZE LAZILY TO CIRCUMVENT SYNCHRONIZATION!" + NL + " */" + NL //$NON-NLS-1$ //$NON-NLS-2$
- + " PRIVATE QUEUE<CHANNELLISTENER> CHANNELLISTENERS = NEW CONCURRENTLINKEDQUEUE();" + NL + "" + NL + " /**" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- + NL + " * IS REGISTERED WITH EACH {@LINK CHANNEL} OF THIS {@LINK CONNECTOR}." + NL + " * <P>" + NL //$NON-NLS-1$ //$NON-NLS-2$
- + " */" + NL + " PRIVATE LIFECYCLELISTENER CHANNELLIFECYCLELISTENER = NEW CHANNELLIFECYCLELISTENER();" + NL //$NON-NLS-1$ //$NON-NLS-2$
- + "" + NL + " PRIVATE COUNTDOWNLATCH FINISHEDCONNECTING;" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- + " PRIVATE COUNTDOWNLATCH FINISHEDNEGOTIATING;" + NL + "" + NL + " PUBLIC ABSTRACTCONNECTOR()" + NL + " {" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- + NL + " }" + NL + "" + NL + " PUBLIC EXECUTORSERVICE GETRECEIVEEXECUTOR()" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- + " RETURN RECEIVEEXECUTOR;" + NL + " }" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- + " PUBLIC VOID SETRECEIVEEXECUTOR(EXECUTORSERVICE RECEIVEEXECUTOR)" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$
- + " THIS.RECEIVEEXECUTOR = RECEIVEEXECUTOR;" + NL + " }" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- + " PUBLIC IREGISTRY<STRING, PROTOCOLFACTORY> GETPROTOCOLFACTORYREGISTRY()" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$
- + " RETURN PROTOCOLFACTORYREGISTRY;" + NL + " }" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- + " PUBLIC VOID SETPROTOCOLFACTORYREGISTRY(IREGISTRY<STRING, PROTOCOLFACTORY> PROTOCOLFACTORYREGISTRY)" + NL //$NON-NLS-1$
- + " {" + NL + " THIS.PROTOCOLFACTORYREGISTRY = PROTOCOLFACTORYREGISTRY;" + NL + " }" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- + " PUBLIC VOID ADDSTATELISTENER(STATELISTENER LISTENER)" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$
- + " STATELISTENERS.ADD(LISTENER);" + NL + " }" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- + " PUBLIC VOID REMOVESTATELISTENER(STATELISTENER LISTENER)" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$
- + " STATELISTENERS.REMOVE(LISTENER);" + NL + " }" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- + " PUBLIC VOID ADDCHANNELLISTENER(CHANNELLISTENER LISTENER)" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$
- + " CHANNELLISTENERS.ADD(LISTENER);" + NL + " }" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- + " PUBLIC VOID REMOVECHANNELLISTENER(CHANNELLISTENER LISTENER)" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$
- + " CHANNELLISTENERS.REMOVE(LISTENER);" + NL + " }" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- + " PUBLIC BUFFERPROVIDER GETBUFFERPROVIDER()" + NL + " {" + NL + " RETURN BUFFERPROVIDER;" + NL + " }" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- + NL + "" + NL + " PUBLIC VOID SETBUFFERPROVIDER(BUFFERPROVIDER BUFFERPROVIDER)" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- + " THIS.BUFFERPROVIDER = BUFFERPROVIDER;" + NL + " }" + NL + "" + NL + " PUBLIC BOOLEAN ISCLIENT()" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- + " {" + NL + " RETURN GETTYPE() == TYPE.CLIENT;" + NL + " }" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- + " PUBLIC BOOLEAN ISSERVER()" + NL + " {" + NL + " RETURN GETTYPE() == TYPE.SERVER;" + NL + " }" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- + "" + NL + " PUBLIC CONNECTORCREDENTIALS GETCREDENTIALS()" + NL + " {" + NL + " RETURN CREDENTIALS;" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- + " }" + NL + "" + NL + " PUBLIC VOID SETCREDENTIALS(CONNECTORCREDENTIALS CREDENTIALS)" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- + " THIS.CREDENTIALS = CREDENTIALS;" + NL + " }" + NL + "" + NL + " PUBLIC STATE GETSTATE()" + NL + " {" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
- + NL + " RETURN STATE;" + NL + " }" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- + " PUBLIC VOID SETSTATE(STATE NEWSTATE) THROWS CONNECTOREXCEPTION" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$
- + " STATE OLDSTATE = GETSTATE();" + NL + " IF (NEWSTATE != OLDSTATE)" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- + " IOUTIL.OUT().PRINTLN(TOSTRING() + \": SETTING STATE \" + NEWSTATE + \" (WAS \"" + NL //$NON-NLS-1$
- + " + OLDSTATE.TOSTRING().TOLOWERCASE() + \")\");" + NL + " STATE = NEWSTATE;" + NL //$NON-NLS-1$ //$NON-NLS-2$
- + " FIRESTATECHANGED(NEWSTATE, OLDSTATE);" + NL + "" + NL + " SWITCH (NEWSTATE)" + NL + " {" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- + NL + " CASE DISCONNECTED:" + NL + " IF (FINISHEDCONNECTING != NULL)" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- + " FINISHEDCONNECTING.COUNTDOWN();" + NL + " FINISHEDCONNECTING = NULL;" + NL + " }" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- + NL + "" + NL + " IF (FINISHEDNEGOTIATING != NULL)" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- + " FINISHEDNEGOTIATING.COUNTDOWN();" + NL + " FINISHEDNEGOTIATING = NULL;" + NL //$NON-NLS-1$ //$NON-NLS-2$
- + " }" + NL + " BREAK;" + NL + "" + NL + " CASE CONNECTING:" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- + " FINISHEDCONNECTING = NEW COUNTDOWNLATCH(1);" + NL //$NON-NLS-1$
- + " FINISHEDNEGOTIATING = NEW COUNTDOWNLATCH(1);" + NL + " IF (GETTYPE() == TYPE.SERVER)" + NL //$NON-NLS-1$ //$NON-NLS-2$
- + " {" + NL + " SETSTATE(STATE.NEGOTIATING);" + NL + " }" + NL + " BREAK;" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- + "" + NL + " CASE NEGOTIATING:" + NL + " FINISHEDCONNECTING.COUNTDOWN();" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- + " SETSTATE(STATE.CONNECTED); // TODO IMPLEMENT NEGOTIATION" + NL + " BREAK;" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- + " CASE CONNECTED:" + NL + " FINISHEDCONNECTING.COUNTDOWN(); // JUST IN CASE OF SUSPICION" + NL //$NON-NLS-1$ //$NON-NLS-2$
- + " FINISHEDNEGOTIATING.COUNTDOWN();" + NL + " BREAK;" + NL + "" + NL + " }" + NL + " }" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
- + NL + " }" + NL + "" + NL + " PUBLIC BOOLEAN ISCONNECTED()" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- + " RETURN GETSTATE() == STATE.CONNECTED;" + NL + " }" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- + " PUBLIC VOID CONNECTASYNC() THROWS CONNECTOREXCEPTION" + NL + " {" + NL + " TRY" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- + " ACTIVATE();" + NL + " }" + NL + " CATCH (CONNECTOREXCEPTION EX)" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- + " THROW EX;" + NL + " }" + NL + " CATCH (EXCEPTION EX)" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- + " THROW NEW CONNECTOREXCEPTION(EX);" + NL + " }" + NL + " }" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- + " PUBLIC BOOLEAN WAITFORCONNECTION(LONG TIMEOUT) THROWS CONNECTOREXCEPTION" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$
- + " STATE STATE = GETSTATE();" + NL + " IF (STATE == STATE.DISCONNECTED)" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- + " RETURN FALSE;" + NL + " }" + NL + "" + NL + " TRY" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
- + " IOUTIL.OUT().PRINTLN(TOSTRING() + \": WAITING FOR CONNECTION...\");" + NL //$NON-NLS-1$
- + " RETURN FINISHEDNEGOTIATING.AWAIT(TIMEOUT, TIMEUNIT.MILLISECONDS);" + NL + " }" + NL //$NON-NLS-1$ //$NON-NLS-2$
- + " CATCH (INTERRUPTEDEXCEPTION EX)" + NL + " {" + NL + " RETURN FALSE;" + NL + " }" + NL + " }" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
- + NL + "" + NL + " PUBLIC BOOLEAN CONNECT(LONG TIMEOUT) THROWS CONNECTOREXCEPTION" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- + " CONNECTASYNC();" + NL + " RETURN WAITFORCONNECTION(TIMEOUT);" + NL + " }" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- + " PUBLIC CONNECTOREXCEPTION DISCONNECT()" + NL + " {" + NL + " EXCEPTION EX = DEACTIVATE();" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- + " IF (EX == NULL)" + NL + " {" + NL + " RETURN NULL;" + NL + " }" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
- + " IF (EX INSTANCEOF CONNECTOREXCEPTION)" + NL + " {" + NL + " RETURN (CONNECTOREXCEPTION)EX;" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- + " }" + NL + "" + NL + " RETURN NEW CONNECTOREXCEPTION(EX);" + NL + " }" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
- + " PUBLIC CHANNEL[] GETCHANNELS()" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$
- + " FINAL LIST<CHANNEL> RESULT = NEW ARRAYLIST<CHANNEL>();" + NL + " SYNCHRONIZED (CHANNELS)" + NL //$NON-NLS-1$ //$NON-NLS-2$
- + " {" + NL + " FOR (FINAL CHANNELIMPL CHANNEL : CHANNELS)" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- + " IF (CHANNEL != NULL_CHANNEL)" + NL + " {" + NL + " RESULT.ADD(CHANNEL);" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- + " }" + NL + " }" + NL + " }" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- + " RETURN RESULT.TOARRAY(NEW CHANNEL[RESULT.SIZE()]);" + NL + " }" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- + " PUBLIC CHANNEL OPENCHANNEL() THROWS CONNECTOREXCEPTION" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$
- + " RETURN OPENCHANNEL(NULL);" + NL + " }" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- + " PUBLIC CHANNEL OPENCHANNEL(STRING PROTOCOLID) THROWS CONNECTOREXCEPTION" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$
- + " SHORT CHANNELINDEX = FINDFREECHANNELINDEX();" + NL //$NON-NLS-1$
- + " CHANNELIMPL CHANNEL = CREATECHANNEL(CHANNELINDEX, PROTOCOLID);" + NL //$NON-NLS-1$
- + " REGISTERCHANNELWITHPEER(CHANNELINDEX, PROTOCOLID);" + NL + "" + NL + " TRY" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- + " CHANNEL.ACTIVATE();" + NL + " }" + NL + " CATCH (CONNECTOREXCEPTION EX)" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- + " THROW EX;" + NL + " }" + NL + " CATCH (EXCEPTION EX)" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- + " THROW NEW CONNECTOREXCEPTION(EX);" + NL + " }" + NL + "" + NL + " RETURN CHANNEL;" + NL + " }" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
- + NL + "" + NL + " PUBLIC CHANNELIMPL CREATECHANNEL(SHORT CHANNELINDEX, STRING PROTOCOLID)" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- + " PROTOCOL PROTOCOL = CREATEPROTOCOL(PROTOCOLID);" + NL + " IF (PROTOCOL == NULL)" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- + " IOUTIL.OUT().PRINTLN(TOSTRING() + \": OPENING CHANNEL WITHOUT PROTOCOL\");" + NL + " }" + NL //$NON-NLS-1$ //$NON-NLS-2$
- + " ELSE" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$
- + " IOUTIL.OUT().PRINTLN(TOSTRING() + \": OPENING CHANNEL WITH PROTOCOL \" + PROTOCOLID);" + NL + " }" //$NON-NLS-1$ //$NON-NLS-2$
- + NL + "" + NL + " CHANNELIMPL CHANNEL = NEW CHANNELIMPL(RECEIVEEXECUTOR);" + NL //$NON-NLS-1$ //$NON-NLS-2$
- + " CHANNEL.SETCHANNELINDEX(CHANNELINDEX);" + NL + " CHANNEL.SETMULTIPLEXER(THIS);" + NL //$NON-NLS-1$ //$NON-NLS-2$
- + " CHANNEL.SETRECEIVEHANDLER(PROTOCOL);" + NL //$NON-NLS-1$
- + " CHANNEL.ADDLIFECYCLELISTENER(CHANNELLIFECYCLELISTENER);" + NL + " ADDCHANNEL(CHANNEL);" + NL //$NON-NLS-1$ //$NON-NLS-2$
- + " RETURN CHANNEL;" + NL + " }" + NL + "" + NL + " PUBLIC CHANNELIMPL GETCHANNEL(SHORT CHANNELINDEX)" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- + NL + " {" + NL + " TRY" + NL + " {" + NL + " CHANNELIMPL CHANNEL = CHANNELS.GET(CHANNELINDEX);" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- + NL + " IF (CHANNEL == NULL || CHANNEL == NULL_CHANNEL)" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$
- + " THROW NEW NULLPOINTEREXCEPTION();" + NL + " }" + NL + "" + NL + " RETURN CHANNEL;" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- + " }" + NL + " CATCH (INDEXOUTOFBOUNDSEXCEPTION EX)" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- + " IOUTIL.OUT().PRINTLN(TOSTRING() + \": INVALID CHANNELINDEX \" + CHANNELINDEX);" + NL //$NON-NLS-1$
- + " RETURN NULL;" + NL + " }" + NL + " }" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- + " PROTECTED LIST<BUFFERQUEUE> GETCHANNELBUFFERQUEUES()" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$
- + " FINAL LIST<BUFFERQUEUE> RESULT = NEW ARRAYLIST<BUFFERQUEUE>();" + NL + " SYNCHRONIZED (CHANNELS)" //$NON-NLS-1$ //$NON-NLS-2$
- + NL + " {" + NL + " FOR (FINAL CHANNELIMPL CHANNEL : CHANNELS)" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- + " IF (CHANNEL != NULL_CHANNEL)" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$
- + " BUFFERQUEUE BUFFERQUEUE = CHANNEL.GETSENDQUEUE();" + NL + " RESULT.ADD(BUFFERQUEUE);" //$NON-NLS-1$ //$NON-NLS-2$
- + NL + " }" + NL + " }" + NL + " }" + NL + "" + NL + " RETURN RESULT;" + NL + " }" + NL + "" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
- + NL + " PROTECTED SHORT FINDFREECHANNELINDEX()" + NL + " {" + NL + " SYNCHRONIZED (CHANNELS)" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- + " {" + NL + " INT SIZE = CHANNELS.SIZE();" + NL + " FOR (SHORT I = 0; I < SIZE; I++)" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- + " {" + NL + " IF (CHANNELS.GET(I) == NULL_CHANNEL)" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- + " RETURN I;" + NL + " }" + NL + " }" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- + " CHANNELS.ADD(NULL_CHANNEL);" + NL + " RETURN (SHORT)SIZE;" + NL + " }" + NL + " }" + NL + "" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
- + NL + " PROTECTED VOID ADDCHANNEL(CHANNELIMPL CHANNEL)" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$
- + " SHORT CHANNELINDEX = CHANNEL.GETCHANNELINDEX();" + NL + " WHILE (CHANNELINDEX >= CHANNELS.SIZE())" //$NON-NLS-1$ //$NON-NLS-2$
- + NL + " {" + NL + " CHANNELS.ADD(NULL_CHANNEL);" + NL + " }" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- + " CHANNELS.SET(CHANNELINDEX, CHANNEL);" + NL + " }" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- + " PROTECTED VOID REMOVECHANNEL(CHANNELIMPL CHANNEL)" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$
- + " CHANNEL.REMOVELIFECYCLELISTENER(CHANNELLIFECYCLELISTENER);" + NL //$NON-NLS-1$
- + " INT CHANNELINDEX = CHANNEL.GETCHANNELINDEX();" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$
- + " IOUTIL.OUT().PRINTLN(TOSTRING() + \": REMOVING CHANNEL \" + CHANNELINDEX);" + NL //$NON-NLS-1$
- + " CHANNELS.SET(CHANNELINDEX, NULL_CHANNEL);" + NL + " }" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- + " PROTECTED PROTOCOL CREATEPROTOCOL(STRING PROTOCOLID)" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$
- + " IF (PROTOCOLID == NULL || PROTOCOLID.LENGTH() == 0)" + NL + " {" + NL + " RETURN NULL;" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- + " }" + NL + "" + NL + " IREGISTRY<STRING, PROTOCOLFACTORY> REGISTRY = GETPROTOCOLFACTORYREGISTRY();" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- + NL + " IF (REGISTRY == NULL)" + NL + " {" + NL + " RETURN NULL;" + NL + " }" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
- + " PROTOCOLFACTORY FACTORY = REGISTRY.LOOKUP(PROTOCOLID);" + NL + " IF (FACTORY == NULL)" + NL + " {" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- + NL + " RETURN NULL;" + NL + " }" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- + " IOUTIL.OUT().PRINTLN(TOSTRING() + \": CREATING PROTOCOL \" + PROTOCOLID);" + NL //$NON-NLS-1$
- + " RETURN FACTORY.CREATEPROTOCOL();" + NL + " }" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- + " PROTECTED VOID FIRECHANNELOPENED(CHANNEL CHANNEL)" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$
- + " FOR (CHANNELLISTENER LISTENER : CHANNELLISTENERS)" + NL + " {" + NL + " TRY" + NL + " {" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- + NL + " LISTENER.NOTIFYCHANNELOPENED(CHANNEL);" + NL + " }" + NL + " CATCH (EXCEPTION EX)" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- + NL + " {" + NL + " EX.PRINTSTACKTRACE();" + NL + " }" + NL + " }" + NL + " }" + NL + "" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
- + NL + " PROTECTED VOID FIRECHANNELCLOSING(CHANNEL CHANNEL)" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$
- + " FOR (CHANNELLISTENER LISTENER : CHANNELLISTENERS)" + NL + " {" + NL + " TRY" + NL + " {" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- + NL + " LISTENER.NOTIFYCHANNELCLOSING(CHANNEL);" + NL + " }" + NL + " CATCH (EXCEPTION EX)" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- + NL + " {" + NL + " EX.PRINTSTACKTRACE();" + NL + " }" + NL + " }" + NL + " }" + NL + "" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
- + NL + " PROTECTED VOID FIRESTATECHANGED(STATE NEWSTATE, STATE OLDSTATE)" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$
- + " FOR (STATELISTENER LISTENER : STATELISTENERS)" + NL + " {" + NL + " TRY" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- + " LISTENER.NOTIFYSTATECHANGED(THIS, NEWSTATE, OLDSTATE);" + NL + " }" + NL //$NON-NLS-1$ //$NON-NLS-2$
- + " CATCH (EXCEPTION EX)" + NL + " {" + NL + " EX.PRINTSTACKTRACE();" + NL + " }" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- + " }" + NL + " }" + NL + "" + NL + " @OVERRIDE" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- + " PROTECTED VOID ONACCESSBEFOREACTIVATE() THROWS EXCEPTION" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$
- + " SUPER.ONACCESSBEFOREACTIVATE();" + NL + " IF (BUFFERPROVIDER == NULL)" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- + " THROW NEW ILLEGALSTATEEXCEPTION(\"BUFFERPROVIDER == NULL\");" + NL + " }" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- + " IF (PROTOCOLFACTORYREGISTRY == NULL)" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$
- + " IOUTIL.OUT().PRINTLN(TOSTRING() + \": (INFO) PROTOCOLFACTORYREGISTRY == NULL\");" + NL + " }" + NL //$NON-NLS-1$ //$NON-NLS-2$
- + "" + NL + " IF (RECEIVEEXECUTOR == NULL)" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- + " IOUTIL.OUT().PRINTLN(TOSTRING() + \": (INFO) RECEIVEEXECUTOR == NULL\");" + NL + " }" + NL + " }" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- + NL + "" + NL + " @OVERRIDE" + NL + " PROTECTED VOID ONACTIVATE() THROWS EXCEPTION" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- + " SUPER.ONACTIVATE();" + NL + " SETSTATE(STATE.CONNECTING);" + NL + " }" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- + " @OVERRIDE" + NL + " PROTECTED VOID ONDEACTIVATE() THROWS EXCEPTION" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- + " SETSTATE(STATE.DISCONNECTED);" + NL + " FOR (SHORT I = 0; I < CHANNELS.SIZE(); I++)" + NL + " {" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- + NL + " CHANNELIMPL CHANNEL = CHANNELS.GET(I);" + NL + " IF (CHANNEL != NULL)" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- + " LIFECYCLEUTIL.DEACTIVATE(CHANNEL);" + NL + " }" + NL + " }" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- + " CHANNELS.CLEAR();" + NL + " SUPER.ONDEACTIVATE();" + NL + " }" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- + " PROTECTED ABSTRACT VOID REGISTERCHANNELWITHPEER(SHORT CHANNELINDEX, STRING PROTOCOLID)" + NL //$NON-NLS-1$
- + " THROWS CONNECTOREXCEPTION;" + NL + "" + NL + " /**" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- + " * IS REGISTERED WITH EACH {@LINK CHANNEL} OF THIS {@LINK CONNECTOR}." + NL + " * <P>" + NL + " * " //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- + NL + " * @AUTHOR EIKE STEPPER" + NL + " */" + NL //$NON-NLS-1$ //$NON-NLS-2$
- + " PRIVATE FINAL CLASS CHANNELLIFECYCLELISTENER IMPLEMENTS LIFECYCLELISTENER" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$
- + " PUBLIC VOID NOTIFYLIFECYCLEACTIVATED(LIFECYCLENOTIFIER NOTIFIER)" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$
- + " CHANNELIMPL CHANNEL = (CHANNELIMPL)NOTIFIER;" + NL + " FIRECHANNELOPENED(CHANNEL);" + NL //$NON-NLS-1$ //$NON-NLS-2$
- + " }" + NL + "" + NL + " PUBLIC VOID NOTIFYLIFECYCLEDEACTIVATING(LIFECYCLENOTIFIER NOTIFIER)" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- + " {" + NL + " CHANNELIMPL CHANNEL = (CHANNELIMPL)NOTIFIER;" + NL //$NON-NLS-1$ //$NON-NLS-2$
- + " FIRECHANNELCLOSING(CHANNEL);" + NL + " REMOVECHANNEL(CHANNEL);" + NL + " }" + NL + " }" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- + "}" + NL; //$NON-NLS-1$
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.tests.data;
+
+import java.util.StringTokenizer;
+
+/**
+ * @author Eike Stepper
+ */
+public final class HugeData
+{
+ public static final String NL = System.getProperty("line.separator"); //$NON-NLS-1$
+
+ public static StringTokenizer getTokenizer()
+ {
+ return new StringTokenizer(getText(), NL);
+ }
+
+ public static String[] getArray()
+ {
+ return getText().split(NL);
+ }
+
+ public static byte[] getBytes()
+ {
+ return getText().getBytes();
+ }
+
+ public static String getText()
+ {
+ return "/**" + NL //$NON-NLS-1$
+ + " * COPYRIGHT (C) 2004 - 2008 EIKE STEPPER, GERMANY." + NL //$NON-NLS-1$
+ + " * ALL RIGHTS RESERVED. THIS PROGRAM AND THE ACCOMPANYING MATERIALS" + NL //$NON-NLS-1$
+ + " * ARE MADE AVAILABLE UNDER THE TERMS OF THE ECLIPSE PUBLIC LICENSE V1.0" + NL //$NON-NLS-1$
+ + " * WHICH ACCOMPANIES THIS DISTRIBUTION, AND IS AVAILABLE AT" + NL //$NON-NLS-1$
+ + " * HTTP://WWW.ECLIPSE.ORG/LEGAL/EPL-V10.HTML" + NL + " * " + NL + " * CONTRIBUTORS:" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ + " * EIKE STEPPER - INITIAL API AND IMPLEMENTATION" + NL //$NON-NLS-1$
+ + " */" + NL //$NON-NLS-1$
+ + "PACKAGE ORG.ECLIPSE.INTERNAL.NET4J.TRANSPORT.CONNECTOR;" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$
+ + "IMPORT ORG.ECLIPSE.NET4J.TRANSPORT.BUFFER.BUFFERPROVIDER;" + NL //$NON-NLS-1$
+ + "IMPORT ORG.ECLIPSE.NET4J.TRANSPORT.CHANNEL.CHANNEL;" + NL //$NON-NLS-1$
+ + "IMPORT ORG.ECLIPSE.NET4J.TRANSPORT.CHANNEL.MULTIPLEXER;" + NL //$NON-NLS-1$
+ + "IMPORT ORG.ECLIPSE.NET4J.TRANSPORT.CONNECTOR.CONNECTOR;" + NL //$NON-NLS-1$
+ + "IMPORT ORG.ECLIPSE.NET4J.TRANSPORT.CONNECTOR.CONNECTOREXCEPTION;" + NL //$NON-NLS-1$
+ + "IMPORT ORG.ECLIPSE.NET4J.TRANSPORT.CONNECTOR.CREDENTIALS;" + NL //$NON-NLS-1$
+ + "IMPORT ORG.ECLIPSE.NET4J.TRANSPORT.CONNECTOR.PROTOCOL;" + NL //$NON-NLS-1$
+ + "IMPORT ORG.ECLIPSE.NET4J.TRANSPORT.CONNECTOR.PROTOCOLFACTORY;" + NL //$NON-NLS-1$
+ + "IMPORT ORG.ECLIPSE.NET4J.UTIL.LIFECYCLE.LIFECYCLELISTENER;" + NL //$NON-NLS-1$
+ + "IMPORT ORG.ECLIPSE.NET4J.UTIL.LIFECYCLE.LIFECYCLENOTIFIER;" + NL //$NON-NLS-1$
+ + "IMPORT ORG.ECLIPSE.NET4J.UTIL.REGISTRY.IREGISTRY;" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$
+ + "IMPORT ORG.ECLIPSE.INTERNAL.NET4J.TRANSPORT.CHANNEL.CHANNELIMPL;" + NL //$NON-NLS-1$
+ + "IMPORT ORG.ECLIPSE.INTERNAL.NET4J.UTIL.STREAM.BUFFERQUEUE;" + NL //$NON-NLS-1$
+ + "IMPORT ORG.ECLIPSE.INTERNAL.NET4J.UTIL.LIFECYCLE.ABSTRACTCOMPONENT;" + NL //$NON-NLS-1$
+ + "IMPORT ORG.ECLIPSE.INTERNAL.NET4J.UTIL.LIFECYCLE.LIFECYCLEUTIL;" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$
+ + "IMPORT JAVA.UTIL.ARRAYLIST;" + NL + "IMPORT JAVA.UTIL.LIST;" + NL + "IMPORT JAVA.UTIL.QUEUE;" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ + "IMPORT JAVA.UTIL.CONCURRENT.CONCURRENTLINKEDQUEUE;" + NL + "IMPORT JAVA.UTIL.CONCURRENT.COUNTDOWNLATCH;" //$NON-NLS-1$ //$NON-NLS-2$
+ + NL + "IMPORT JAVA.UTIL.CONCURRENT.EXECUTORSERVICE;" + NL + "IMPORT JAVA.UTIL.CONCURRENT.TIMEUNIT;" + NL + "" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ + NL + "/**" + NL + " * @AUTHOR EIKE STEPPER" + NL + " */" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ + "PUBLIC ABSTRACT CLASS ABSTRACTCONNECTOR EXTENDS ABSTRACTLIFECYCLE IMPLEMENTS CONNECTOR, CHANNELMULTIPLEXER" //$NON-NLS-1$
+ + NL + "{" + NL + " PRIVATE STATIC FINAL CHANNELIMPL NULL_CHANNEL = NEW CHANNELIMPL(NULL);" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ + " PRIVATE CONNECTORCREDENTIALS CREDENTIALS;" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$
+ + " PRIVATE IREGISTRY<STRING, PROTOCOLFACTORY> PROTOCOLFACTORYREGISTRY;" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$
+ + " PRIVATE BUFFERPROVIDER BUFFERPROVIDER;" + NL + "" + NL + " /**" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ + " * AN OPTIONAL EXECUTOR TO BE USED BY THE {@LINK CHANNEL}S TO PROCESS THEIR" + NL //$NON-NLS-1$
+ + " * {@LINK CHANNELIMPL#RECEIVEQUEUE} INSTEAD OF THE CURRENT THREAD. IF NOT" + NL //$NON-NLS-1$
+ + " * <CODE>NULL</CODE> THE SENDER AND THE RECEIVER PEERS BECOME DECOUPLED." + NL + " * <P>" + NL + " */" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ + NL + " PRIVATE EXECUTORSERVICE RECEIVEEXECUTOR;" + NL + "" + NL + " /**" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ + " * TODO SYNCHRONIZE ON CHANNELS?" + NL + " */" + NL //$NON-NLS-1$ //$NON-NLS-2$
+ + " PRIVATE LIST<CHANNELIMPL> CHANNELS = NEW ARRAYLIST();" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$
+ + " PRIVATE STATE STATE = STATE.DISCONNECTED;" + NL + "" + NL + " /**" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ + " * DON\'T INITIALIZE LAZILY TO CIRCUMVENT SYNCHRONIZATION!" + NL + " */" + NL //$NON-NLS-1$ //$NON-NLS-2$
+ + " PRIVATE QUEUE<STATELISTENER> STATELISTENERS = NEW CONCURRENTLINKEDQUEUE();" + NL + "" + NL + " /**" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ + " * DON\'T INITIALIZE LAZILY TO CIRCUMVENT SYNCHRONIZATION!" + NL + " */" + NL //$NON-NLS-1$ //$NON-NLS-2$
+ + " PRIVATE QUEUE<CHANNELLISTENER> CHANNELLISTENERS = NEW CONCURRENTLINKEDQUEUE();" + NL + "" + NL + " /**" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ + NL + " * IS REGISTERED WITH EACH {@LINK CHANNEL} OF THIS {@LINK CONNECTOR}." + NL + " * <P>" + NL //$NON-NLS-1$ //$NON-NLS-2$
+ + " */" + NL + " PRIVATE LIFECYCLELISTENER CHANNELLIFECYCLELISTENER = NEW CHANNELLIFECYCLELISTENER();" + NL //$NON-NLS-1$ //$NON-NLS-2$
+ + "" + NL + " PRIVATE COUNTDOWNLATCH FINISHEDCONNECTING;" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ + " PRIVATE COUNTDOWNLATCH FINISHEDNEGOTIATING;" + NL + "" + NL + " PUBLIC ABSTRACTCONNECTOR()" + NL + " {" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ + NL + " }" + NL + "" + NL + " PUBLIC EXECUTORSERVICE GETRECEIVEEXECUTOR()" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ + " RETURN RECEIVEEXECUTOR;" + NL + " }" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ + " PUBLIC VOID SETRECEIVEEXECUTOR(EXECUTORSERVICE RECEIVEEXECUTOR)" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$
+ + " THIS.RECEIVEEXECUTOR = RECEIVEEXECUTOR;" + NL + " }" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ + " PUBLIC IREGISTRY<STRING, PROTOCOLFACTORY> GETPROTOCOLFACTORYREGISTRY()" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$
+ + " RETURN PROTOCOLFACTORYREGISTRY;" + NL + " }" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ + " PUBLIC VOID SETPROTOCOLFACTORYREGISTRY(IREGISTRY<STRING, PROTOCOLFACTORY> PROTOCOLFACTORYREGISTRY)" + NL //$NON-NLS-1$
+ + " {" + NL + " THIS.PROTOCOLFACTORYREGISTRY = PROTOCOLFACTORYREGISTRY;" + NL + " }" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ + " PUBLIC VOID ADDSTATELISTENER(STATELISTENER LISTENER)" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$
+ + " STATELISTENERS.ADD(LISTENER);" + NL + " }" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ + " PUBLIC VOID REMOVESTATELISTENER(STATELISTENER LISTENER)" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$
+ + " STATELISTENERS.REMOVE(LISTENER);" + NL + " }" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ + " PUBLIC VOID ADDCHANNELLISTENER(CHANNELLISTENER LISTENER)" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$
+ + " CHANNELLISTENERS.ADD(LISTENER);" + NL + " }" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ + " PUBLIC VOID REMOVECHANNELLISTENER(CHANNELLISTENER LISTENER)" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$
+ + " CHANNELLISTENERS.REMOVE(LISTENER);" + NL + " }" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ + " PUBLIC BUFFERPROVIDER GETBUFFERPROVIDER()" + NL + " {" + NL + " RETURN BUFFERPROVIDER;" + NL + " }" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ + NL + "" + NL + " PUBLIC VOID SETBUFFERPROVIDER(BUFFERPROVIDER BUFFERPROVIDER)" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ + " THIS.BUFFERPROVIDER = BUFFERPROVIDER;" + NL + " }" + NL + "" + NL + " PUBLIC BOOLEAN ISCLIENT()" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ + " {" + NL + " RETURN GETTYPE() == TYPE.CLIENT;" + NL + " }" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ + " PUBLIC BOOLEAN ISSERVER()" + NL + " {" + NL + " RETURN GETTYPE() == TYPE.SERVER;" + NL + " }" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ + "" + NL + " PUBLIC CONNECTORCREDENTIALS GETCREDENTIALS()" + NL + " {" + NL + " RETURN CREDENTIALS;" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ + " }" + NL + "" + NL + " PUBLIC VOID SETCREDENTIALS(CONNECTORCREDENTIALS CREDENTIALS)" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ + " THIS.CREDENTIALS = CREDENTIALS;" + NL + " }" + NL + "" + NL + " PUBLIC STATE GETSTATE()" + NL + " {" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
+ + NL + " RETURN STATE;" + NL + " }" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ + " PUBLIC VOID SETSTATE(STATE NEWSTATE) THROWS CONNECTOREXCEPTION" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$
+ + " STATE OLDSTATE = GETSTATE();" + NL + " IF (NEWSTATE != OLDSTATE)" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ + " IOUTIL.OUT().PRINTLN(TOSTRING() + \": SETTING STATE \" + NEWSTATE + \" (WAS \"" + NL //$NON-NLS-1$
+ + " + OLDSTATE.TOSTRING().TOLOWERCASE() + \")\");" + NL + " STATE = NEWSTATE;" + NL //$NON-NLS-1$ //$NON-NLS-2$
+ + " FIRESTATECHANGED(NEWSTATE, OLDSTATE);" + NL + "" + NL + " SWITCH (NEWSTATE)" + NL + " {" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ + NL + " CASE DISCONNECTED:" + NL + " IF (FINISHEDCONNECTING != NULL)" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ + " FINISHEDCONNECTING.COUNTDOWN();" + NL + " FINISHEDCONNECTING = NULL;" + NL + " }" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ + NL + "" + NL + " IF (FINISHEDNEGOTIATING != NULL)" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ + " FINISHEDNEGOTIATING.COUNTDOWN();" + NL + " FINISHEDNEGOTIATING = NULL;" + NL //$NON-NLS-1$ //$NON-NLS-2$
+ + " }" + NL + " BREAK;" + NL + "" + NL + " CASE CONNECTING:" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ + " FINISHEDCONNECTING = NEW COUNTDOWNLATCH(1);" + NL //$NON-NLS-1$
+ + " FINISHEDNEGOTIATING = NEW COUNTDOWNLATCH(1);" + NL + " IF (GETTYPE() == TYPE.SERVER)" + NL //$NON-NLS-1$ //$NON-NLS-2$
+ + " {" + NL + " SETSTATE(STATE.NEGOTIATING);" + NL + " }" + NL + " BREAK;" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ + "" + NL + " CASE NEGOTIATING:" + NL + " FINISHEDCONNECTING.COUNTDOWN();" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ + " SETSTATE(STATE.CONNECTED); // TODO IMPLEMENT NEGOTIATION" + NL + " BREAK;" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ + " CASE CONNECTED:" + NL + " FINISHEDCONNECTING.COUNTDOWN(); // JUST IN CASE OF SUSPICION" + NL //$NON-NLS-1$ //$NON-NLS-2$
+ + " FINISHEDNEGOTIATING.COUNTDOWN();" + NL + " BREAK;" + NL + "" + NL + " }" + NL + " }" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
+ + NL + " }" + NL + "" + NL + " PUBLIC BOOLEAN ISCONNECTED()" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ + " RETURN GETSTATE() == STATE.CONNECTED;" + NL + " }" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ + " PUBLIC VOID CONNECTASYNC() THROWS CONNECTOREXCEPTION" + NL + " {" + NL + " TRY" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ + " ACTIVATE();" + NL + " }" + NL + " CATCH (CONNECTOREXCEPTION EX)" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ + " THROW EX;" + NL + " }" + NL + " CATCH (EXCEPTION EX)" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ + " THROW NEW CONNECTOREXCEPTION(EX);" + NL + " }" + NL + " }" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ + " PUBLIC BOOLEAN WAITFORCONNECTION(LONG TIMEOUT) THROWS CONNECTOREXCEPTION" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$
+ + " STATE STATE = GETSTATE();" + NL + " IF (STATE == STATE.DISCONNECTED)" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ + " RETURN FALSE;" + NL + " }" + NL + "" + NL + " TRY" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
+ + " IOUTIL.OUT().PRINTLN(TOSTRING() + \": WAITING FOR CONNECTION...\");" + NL //$NON-NLS-1$
+ + " RETURN FINISHEDNEGOTIATING.AWAIT(TIMEOUT, TIMEUNIT.MILLISECONDS);" + NL + " }" + NL //$NON-NLS-1$ //$NON-NLS-2$
+ + " CATCH (INTERRUPTEDEXCEPTION EX)" + NL + " {" + NL + " RETURN FALSE;" + NL + " }" + NL + " }" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
+ + NL + "" + NL + " PUBLIC BOOLEAN CONNECT(LONG TIMEOUT) THROWS CONNECTOREXCEPTION" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ + " CONNECTASYNC();" + NL + " RETURN WAITFORCONNECTION(TIMEOUT);" + NL + " }" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ + " PUBLIC CONNECTOREXCEPTION DISCONNECT()" + NL + " {" + NL + " EXCEPTION EX = DEACTIVATE();" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ + " IF (EX == NULL)" + NL + " {" + NL + " RETURN NULL;" + NL + " }" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
+ + " IF (EX INSTANCEOF CONNECTOREXCEPTION)" + NL + " {" + NL + " RETURN (CONNECTOREXCEPTION)EX;" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ + " }" + NL + "" + NL + " RETURN NEW CONNECTOREXCEPTION(EX);" + NL + " }" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
+ + " PUBLIC CHANNEL[] GETCHANNELS()" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$
+ + " FINAL LIST<CHANNEL> RESULT = NEW ARRAYLIST<CHANNEL>();" + NL + " SYNCHRONIZED (CHANNELS)" + NL //$NON-NLS-1$ //$NON-NLS-2$
+ + " {" + NL + " FOR (FINAL CHANNELIMPL CHANNEL : CHANNELS)" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ + " IF (CHANNEL != NULL_CHANNEL)" + NL + " {" + NL + " RESULT.ADD(CHANNEL);" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ + " }" + NL + " }" + NL + " }" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ + " RETURN RESULT.TOARRAY(NEW CHANNEL[RESULT.SIZE()]);" + NL + " }" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ + " PUBLIC CHANNEL OPENCHANNEL() THROWS CONNECTOREXCEPTION" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$
+ + " RETURN OPENCHANNEL(NULL);" + NL + " }" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ + " PUBLIC CHANNEL OPENCHANNEL(STRING PROTOCOLID) THROWS CONNECTOREXCEPTION" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$
+ + " SHORT CHANNELINDEX = FINDFREECHANNELINDEX();" + NL //$NON-NLS-1$
+ + " CHANNELIMPL CHANNEL = CREATECHANNEL(CHANNELINDEX, PROTOCOLID);" + NL //$NON-NLS-1$
+ + " REGISTERCHANNELWITHPEER(CHANNELINDEX, PROTOCOLID);" + NL + "" + NL + " TRY" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ + " CHANNEL.ACTIVATE();" + NL + " }" + NL + " CATCH (CONNECTOREXCEPTION EX)" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ + " THROW EX;" + NL + " }" + NL + " CATCH (EXCEPTION EX)" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ + " THROW NEW CONNECTOREXCEPTION(EX);" + NL + " }" + NL + "" + NL + " RETURN CHANNEL;" + NL + " }" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
+ + NL + "" + NL + " PUBLIC CHANNELIMPL CREATECHANNEL(SHORT CHANNELINDEX, STRING PROTOCOLID)" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ + " PROTOCOL PROTOCOL = CREATEPROTOCOL(PROTOCOLID);" + NL + " IF (PROTOCOL == NULL)" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ + " IOUTIL.OUT().PRINTLN(TOSTRING() + \": OPENING CHANNEL WITHOUT PROTOCOL\");" + NL + " }" + NL //$NON-NLS-1$ //$NON-NLS-2$
+ + " ELSE" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$
+ + " IOUTIL.OUT().PRINTLN(TOSTRING() + \": OPENING CHANNEL WITH PROTOCOL \" + PROTOCOLID);" + NL + " }" //$NON-NLS-1$ //$NON-NLS-2$
+ + NL + "" + NL + " CHANNELIMPL CHANNEL = NEW CHANNELIMPL(RECEIVEEXECUTOR);" + NL //$NON-NLS-1$ //$NON-NLS-2$
+ + " CHANNEL.SETCHANNELINDEX(CHANNELINDEX);" + NL + " CHANNEL.SETMULTIPLEXER(THIS);" + NL //$NON-NLS-1$ //$NON-NLS-2$
+ + " CHANNEL.SETRECEIVEHANDLER(PROTOCOL);" + NL //$NON-NLS-1$
+ + " CHANNEL.ADDLIFECYCLELISTENER(CHANNELLIFECYCLELISTENER);" + NL + " ADDCHANNEL(CHANNEL);" + NL //$NON-NLS-1$ //$NON-NLS-2$
+ + " RETURN CHANNEL;" + NL + " }" + NL + "" + NL + " PUBLIC CHANNELIMPL GETCHANNEL(SHORT CHANNELINDEX)" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ + NL + " {" + NL + " TRY" + NL + " {" + NL + " CHANNELIMPL CHANNEL = CHANNELS.GET(CHANNELINDEX);" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ + NL + " IF (CHANNEL == NULL || CHANNEL == NULL_CHANNEL)" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$
+ + " THROW NEW NULLPOINTEREXCEPTION();" + NL + " }" + NL + "" + NL + " RETURN CHANNEL;" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ + " }" + NL + " CATCH (INDEXOUTOFBOUNDSEXCEPTION EX)" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ + " IOUTIL.OUT().PRINTLN(TOSTRING() + \": INVALID CHANNELINDEX \" + CHANNELINDEX);" + NL //$NON-NLS-1$
+ + " RETURN NULL;" + NL + " }" + NL + " }" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ + " PROTECTED LIST<BUFFERQUEUE> GETCHANNELBUFFERQUEUES()" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$
+ + " FINAL LIST<BUFFERQUEUE> RESULT = NEW ARRAYLIST<BUFFERQUEUE>();" + NL + " SYNCHRONIZED (CHANNELS)" //$NON-NLS-1$ //$NON-NLS-2$
+ + NL + " {" + NL + " FOR (FINAL CHANNELIMPL CHANNEL : CHANNELS)" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ + " IF (CHANNEL != NULL_CHANNEL)" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$
+ + " BUFFERQUEUE BUFFERQUEUE = CHANNEL.GETSENDQUEUE();" + NL + " RESULT.ADD(BUFFERQUEUE);" //$NON-NLS-1$ //$NON-NLS-2$
+ + NL + " }" + NL + " }" + NL + " }" + NL + "" + NL + " RETURN RESULT;" + NL + " }" + NL + "" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
+ + NL + " PROTECTED SHORT FINDFREECHANNELINDEX()" + NL + " {" + NL + " SYNCHRONIZED (CHANNELS)" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ + " {" + NL + " INT SIZE = CHANNELS.SIZE();" + NL + " FOR (SHORT I = 0; I < SIZE; I++)" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ + " {" + NL + " IF (CHANNELS.GET(I) == NULL_CHANNEL)" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ + " RETURN I;" + NL + " }" + NL + " }" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ + " CHANNELS.ADD(NULL_CHANNEL);" + NL + " RETURN (SHORT)SIZE;" + NL + " }" + NL + " }" + NL + "" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
+ + NL + " PROTECTED VOID ADDCHANNEL(CHANNELIMPL CHANNEL)" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$
+ + " SHORT CHANNELINDEX = CHANNEL.GETCHANNELINDEX();" + NL + " WHILE (CHANNELINDEX >= CHANNELS.SIZE())" //$NON-NLS-1$ //$NON-NLS-2$
+ + NL + " {" + NL + " CHANNELS.ADD(NULL_CHANNEL);" + NL + " }" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ + " CHANNELS.SET(CHANNELINDEX, CHANNEL);" + NL + " }" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ + " PROTECTED VOID REMOVECHANNEL(CHANNELIMPL CHANNEL)" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$
+ + " CHANNEL.REMOVELIFECYCLELISTENER(CHANNELLIFECYCLELISTENER);" + NL //$NON-NLS-1$
+ + " INT CHANNELINDEX = CHANNEL.GETCHANNELINDEX();" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$
+ + " IOUTIL.OUT().PRINTLN(TOSTRING() + \": REMOVING CHANNEL \" + CHANNELINDEX);" + NL //$NON-NLS-1$
+ + " CHANNELS.SET(CHANNELINDEX, NULL_CHANNEL);" + NL + " }" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ + " PROTECTED PROTOCOL CREATEPROTOCOL(STRING PROTOCOLID)" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$
+ + " IF (PROTOCOLID == NULL || PROTOCOLID.LENGTH() == 0)" + NL + " {" + NL + " RETURN NULL;" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ + " }" + NL + "" + NL + " IREGISTRY<STRING, PROTOCOLFACTORY> REGISTRY = GETPROTOCOLFACTORYREGISTRY();" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ + NL + " IF (REGISTRY == NULL)" + NL + " {" + NL + " RETURN NULL;" + NL + " }" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
+ + " PROTOCOLFACTORY FACTORY = REGISTRY.LOOKUP(PROTOCOLID);" + NL + " IF (FACTORY == NULL)" + NL + " {" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ + NL + " RETURN NULL;" + NL + " }" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ + " IOUTIL.OUT().PRINTLN(TOSTRING() + \": CREATING PROTOCOL \" + PROTOCOLID);" + NL //$NON-NLS-1$
+ + " RETURN FACTORY.CREATEPROTOCOL();" + NL + " }" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ + " PROTECTED VOID FIRECHANNELOPENED(CHANNEL CHANNEL)" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$
+ + " FOR (CHANNELLISTENER LISTENER : CHANNELLISTENERS)" + NL + " {" + NL + " TRY" + NL + " {" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ + NL + " LISTENER.NOTIFYCHANNELOPENED(CHANNEL);" + NL + " }" + NL + " CATCH (EXCEPTION EX)" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ + NL + " {" + NL + " EX.PRINTSTACKTRACE();" + NL + " }" + NL + " }" + NL + " }" + NL + "" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
+ + NL + " PROTECTED VOID FIRECHANNELCLOSING(CHANNEL CHANNEL)" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$
+ + " FOR (CHANNELLISTENER LISTENER : CHANNELLISTENERS)" + NL + " {" + NL + " TRY" + NL + " {" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ + NL + " LISTENER.NOTIFYCHANNELCLOSING(CHANNEL);" + NL + " }" + NL + " CATCH (EXCEPTION EX)" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ + NL + " {" + NL + " EX.PRINTSTACKTRACE();" + NL + " }" + NL + " }" + NL + " }" + NL + "" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
+ + NL + " PROTECTED VOID FIRESTATECHANGED(STATE NEWSTATE, STATE OLDSTATE)" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$
+ + " FOR (STATELISTENER LISTENER : STATELISTENERS)" + NL + " {" + NL + " TRY" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ + " LISTENER.NOTIFYSTATECHANGED(THIS, NEWSTATE, OLDSTATE);" + NL + " }" + NL //$NON-NLS-1$ //$NON-NLS-2$
+ + " CATCH (EXCEPTION EX)" + NL + " {" + NL + " EX.PRINTSTACKTRACE();" + NL + " }" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ + " }" + NL + " }" + NL + "" + NL + " @OVERRIDE" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ + " PROTECTED VOID ONACCESSBEFOREACTIVATE() THROWS EXCEPTION" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$
+ + " SUPER.ONACCESSBEFOREACTIVATE();" + NL + " IF (BUFFERPROVIDER == NULL)" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ + " THROW NEW ILLEGALSTATEEXCEPTION(\"BUFFERPROVIDER == NULL\");" + NL + " }" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ + " IF (PROTOCOLFACTORYREGISTRY == NULL)" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$
+ + " IOUTIL.OUT().PRINTLN(TOSTRING() + \": (INFO) PROTOCOLFACTORYREGISTRY == NULL\");" + NL + " }" + NL //$NON-NLS-1$ //$NON-NLS-2$
+ + "" + NL + " IF (RECEIVEEXECUTOR == NULL)" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ + " IOUTIL.OUT().PRINTLN(TOSTRING() + \": (INFO) RECEIVEEXECUTOR == NULL\");" + NL + " }" + NL + " }" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ + NL + "" + NL + " @OVERRIDE" + NL + " PROTECTED VOID ONACTIVATE() THROWS EXCEPTION" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ + " SUPER.ONACTIVATE();" + NL + " SETSTATE(STATE.CONNECTING);" + NL + " }" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ + " @OVERRIDE" + NL + " PROTECTED VOID ONDEACTIVATE() THROWS EXCEPTION" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ + " SETSTATE(STATE.DISCONNECTED);" + NL + " FOR (SHORT I = 0; I < CHANNELS.SIZE(); I++)" + NL + " {" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ + NL + " CHANNELIMPL CHANNEL = CHANNELS.GET(I);" + NL + " IF (CHANNEL != NULL)" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ + " LIFECYCLEUTIL.DEACTIVATE(CHANNEL);" + NL + " }" + NL + " }" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ + " CHANNELS.CLEAR();" + NL + " SUPER.ONDEACTIVATE();" + NL + " }" + NL + "" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ + " PROTECTED ABSTRACT VOID REGISTERCHANNELWITHPEER(SHORT CHANNELINDEX, STRING PROTOCOLID)" + NL //$NON-NLS-1$
+ + " THROWS CONNECTOREXCEPTION;" + NL + "" + NL + " /**" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ + " * IS REGISTERED WITH EACH {@LINK CHANNEL} OF THIS {@LINK CONNECTOR}." + NL + " * <P>" + NL + " * " //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ + NL + " * @AUTHOR EIKE STEPPER" + NL + " */" + NL //$NON-NLS-1$ //$NON-NLS-2$
+ + " PRIVATE FINAL CLASS CHANNELLIFECYCLELISTENER IMPLEMENTS LIFECYCLELISTENER" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$
+ + " PUBLIC VOID NOTIFYLIFECYCLEACTIVATED(LIFECYCLENOTIFIER NOTIFIER)" + NL + " {" + NL //$NON-NLS-1$ //$NON-NLS-2$
+ + " CHANNELIMPL CHANNEL = (CHANNELIMPL)NOTIFIER;" + NL + " FIRECHANNELOPENED(CHANNEL);" + NL //$NON-NLS-1$ //$NON-NLS-2$
+ + " }" + NL + "" + NL + " PUBLIC VOID NOTIFYLIFECYCLEDEACTIVATING(LIFECYCLENOTIFIER NOTIFIER)" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ + " {" + NL + " CHANNELIMPL CHANNEL = (CHANNELIMPL)NOTIFIER;" + NL //$NON-NLS-1$ //$NON-NLS-2$
+ + " FIRECHANNELCLOSING(CHANNEL);" + NL + " REMOVECHANNEL(CHANNEL);" + NL + " }" + NL + " }" + NL //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ + "}" + NL; //$NON-NLS-1$
+ }
+}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/data/TinyData.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/data/TinyData.java
index 0a4b663cd2..cc6d06a7f0 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/data/TinyData.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/data/TinyData.java
@@ -1,41 +1,41 @@
-/*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- */
-package org.eclipse.net4j.tests.data;
-
-import java.util.StringTokenizer;
-
-/**
- * @author Eike Stepper
- */
-public final class TinyData
-{
- public static final String NL = System.getProperty("line.separator"); //$NON-NLS-1$
-
- public static StringTokenizer getTokenizer()
- {
- return new StringTokenizer(getText(), NL);
- }
-
- public static String[] getArray()
- {
- return getText().split(NL);
- }
-
- public static byte[] getBytes()
- {
- return getText().getBytes();
- }
-
- public static String getText()
- {
- return "COPYRIGHT (C) 2004 - 2008 EIKE STEPPER, GERMANY. ALL RIGHTS RESERVED."; //$NON-NLS-1$
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.tests.data;
+
+import java.util.StringTokenizer;
+
+/**
+ * @author Eike Stepper
+ */
+public final class TinyData
+{
+ public static final String NL = System.getProperty("line.separator"); //$NON-NLS-1$
+
+ public static StringTokenizer getTokenizer()
+ {
+ return new StringTokenizer(getText(), NL);
+ }
+
+ public static String[] getArray()
+ {
+ return getText().split(NL);
+ }
+
+ public static byte[] getBytes()
+ {
+ return getText().getBytes();
+ }
+
+ public static String getText()
+ {
+ return "COPYRIGHT (C) 2004 - 2008 EIKE STEPPER, GERMANY. ALL RIGHTS RESERVED."; //$NON-NLS-1$
+ }
+}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/defs/JVMAcceptorDefImplTest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/defs/JVMAcceptorDefImplTest.java
index 41649df9f8..5afbfb5b67 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/defs/JVMAcceptorDefImplTest.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/defs/JVMAcceptorDefImplTest.java
@@ -1,95 +1,95 @@
-/*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Andre Dietisheim - initial API and implementation
- * Eike Stepper - maintenance
- */
-package org.eclipse.net4j.tests.defs;
-
-import org.eclipse.net4j.Net4jUtil;
-import org.eclipse.net4j.buffer.IBufferPool;
-import org.eclipse.net4j.defs.JVMAcceptorDef;
-import org.eclipse.net4j.defs.Net4jDefsFactory;
-import org.eclipse.net4j.internal.jvm.JVMClientConnector;
-import org.eclipse.net4j.jvm.IJVMAcceptor;
-import org.eclipse.net4j.jvm.IJVMConnector;
-import org.eclipse.net4j.util.defs.Net4jUtilDefsFactory;
-import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
-import org.eclipse.net4j.util.tests.AbstractOMTest;
-
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-
-/**
- * @author Andre Dietisheim
- */
-public class JVMAcceptorDefImplTest extends AbstractOMTest
-{
- private static final String NAME = "JVMConnector1"; //$NON-NLS-1$
-
- private static final long TIMEOUT = 10000l;
-
- private static final long DELAY = 500l;
-
- private IJVMConnector jvmConnector;
-
- @Override
- protected void doSetUp() throws Exception
- {
- jvmConnector = createJVMClientConnector();
- }
-
- @Override
- protected void doTearDown() throws Exception
- {
- LifecycleUtil.deactivate(jvmConnector);
- }
-
- public void testAcceptorDefOpensConnection()
- {
- JVMAcceptorDef jvmAcceptorDef = Net4jDefsFactory.eINSTANCE.createJVMAcceptorDef();
- jvmAcceptorDef.setBufferProvider(Net4jDefsFactory.eINSTANCE.createBufferPoolDef());
- jvmAcceptorDef.setExecutorService(Net4jUtilDefsFactory.eINSTANCE.createThreadPoolDef());
- jvmAcceptorDef.setName(NAME);
-
- IJVMAcceptor jvmAcceptor = (IJVMAcceptor)jvmAcceptorDef.getInstance();
-
- assertEquals(true, LifecycleUtil.isActive(jvmAcceptor));
-
- LifecycleUtil.activate(jvmConnector);
- jvmConnector.waitForConnection(DELAY + TIMEOUT);
-
- assertEquals(true, LifecycleUtil.isActive(jvmConnector));
-
- LifecycleUtil.deactivate(jvmAcceptor);
- }
-
- protected IJVMConnector createJVMClientConnector()
- {
- JVMClientConnector jvmClientConnector = new JVMClientConnector();
- jvmClientConnector.getConfig().setBufferProvider(createBufferPool());
- jvmClientConnector.getConfig().setReceiveExecutor(createThreadPool());
- jvmClientConnector.setName(NAME);
-
- return jvmClientConnector;
- }
-
- private IBufferPool createBufferPool()
- {
- IBufferPool bufferPool = Net4jUtil.createBufferPool();
- LifecycleUtil.activate(bufferPool);
- return bufferPool;
- }
-
- private ExecutorService createThreadPool()
- {
- ExecutorService threadPool = Executors.newCachedThreadPool();
- LifecycleUtil.activate(threadPool);
- return threadPool;
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Andre Dietisheim - initial API and implementation
+ * Eike Stepper - maintenance
+ */
+package org.eclipse.net4j.tests.defs;
+
+import org.eclipse.net4j.Net4jUtil;
+import org.eclipse.net4j.buffer.IBufferPool;
+import org.eclipse.net4j.defs.JVMAcceptorDef;
+import org.eclipse.net4j.defs.Net4jDefsFactory;
+import org.eclipse.net4j.internal.jvm.JVMClientConnector;
+import org.eclipse.net4j.jvm.IJVMAcceptor;
+import org.eclipse.net4j.jvm.IJVMConnector;
+import org.eclipse.net4j.util.defs.Net4jUtilDefsFactory;
+import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
+import org.eclipse.net4j.util.tests.AbstractOMTest;
+
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+/**
+ * @author Andre Dietisheim
+ */
+public class JVMAcceptorDefImplTest extends AbstractOMTest
+{
+ private static final String NAME = "JVMConnector1"; //$NON-NLS-1$
+
+ private static final long TIMEOUT = 10000l;
+
+ private static final long DELAY = 500l;
+
+ private IJVMConnector jvmConnector;
+
+ @Override
+ protected void doSetUp() throws Exception
+ {
+ jvmConnector = createJVMClientConnector();
+ }
+
+ @Override
+ protected void doTearDown() throws Exception
+ {
+ LifecycleUtil.deactivate(jvmConnector);
+ }
+
+ public void testAcceptorDefOpensConnection()
+ {
+ JVMAcceptorDef jvmAcceptorDef = Net4jDefsFactory.eINSTANCE.createJVMAcceptorDef();
+ jvmAcceptorDef.setBufferProvider(Net4jDefsFactory.eINSTANCE.createBufferPoolDef());
+ jvmAcceptorDef.setExecutorService(Net4jUtilDefsFactory.eINSTANCE.createThreadPoolDef());
+ jvmAcceptorDef.setName(NAME);
+
+ IJVMAcceptor jvmAcceptor = (IJVMAcceptor)jvmAcceptorDef.getInstance();
+
+ assertEquals(true, LifecycleUtil.isActive(jvmAcceptor));
+
+ LifecycleUtil.activate(jvmConnector);
+ jvmConnector.waitForConnection(DELAY + TIMEOUT);
+
+ assertEquals(true, LifecycleUtil.isActive(jvmConnector));
+
+ LifecycleUtil.deactivate(jvmAcceptor);
+ }
+
+ protected IJVMConnector createJVMClientConnector()
+ {
+ JVMClientConnector jvmClientConnector = new JVMClientConnector();
+ jvmClientConnector.getConfig().setBufferProvider(createBufferPool());
+ jvmClientConnector.getConfig().setReceiveExecutor(createThreadPool());
+ jvmClientConnector.setName(NAME);
+
+ return jvmClientConnector;
+ }
+
+ private IBufferPool createBufferPool()
+ {
+ IBufferPool bufferPool = Net4jUtil.createBufferPool();
+ LifecycleUtil.activate(bufferPool);
+ return bufferPool;
+ }
+
+ private ExecutorService createThreadPool()
+ {
+ ExecutorService threadPool = Executors.newCachedThreadPool();
+ LifecycleUtil.activate(threadPool);
+ return threadPool;
+ }
+}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/defs/JVMConnectorDefImplTest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/defs/JVMConnectorDefImplTest.java
index c34caf1410..a8173c3498 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/defs/JVMConnectorDefImplTest.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/defs/JVMConnectorDefImplTest.java
@@ -1,80 +1,80 @@
-/*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Andre Dietisheim - initial API and implementation
- * Eike Stepper - maintenance
- */
-package org.eclipse.net4j.tests.defs;
-
-import org.eclipse.net4j.Net4jUtil;
-import org.eclipse.net4j.buffer.IBufferPool;
-import org.eclipse.net4j.defs.JVMConnectorDef;
-import org.eclipse.net4j.defs.Net4jDefsFactory;
-import org.eclipse.net4j.internal.jvm.JVMAcceptor;
-import org.eclipse.net4j.jvm.IJVMAcceptor;
-import org.eclipse.net4j.jvm.IJVMConnector;
-import org.eclipse.net4j.util.defs.Net4jUtilDefsFactory;
-import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
-import org.eclipse.net4j.util.tests.AbstractOMTest;
-
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-
-/**
- * @author Andre Dietisheim
- */
-public class JVMConnectorDefImplTest extends AbstractOMTest
-{
- private static final String NAME = "test1"; //$NON-NLS-1$
-
- public void testIncompleteInitializationThrowsIllegalArgumentException()
- {
- try
- {
- Net4jDefsFactory.eINSTANCE.createJVMConnectorDef().getInstance();
- fail("IllegalStateException expected!"); //$NON-NLS-1$
- }
- catch (IllegalStateException e)
- {
- }
- }
-
- public void testConnectorLaunchableOpensConnection()
- {
- IJVMAcceptor jvmAcceptor = createJVMAcceptor();
-
- JVMConnectorDef jvmConnectorDef = Net4jDefsFactory.eINSTANCE.createJVMConnectorDef();
-
- jvmConnectorDef.setBufferProvider(Net4jDefsFactory.eINSTANCE.createBufferPoolDef());
- jvmConnectorDef.setExecutorService(Net4jUtilDefsFactory.eINSTANCE.createThreadPoolDef());
- jvmConnectorDef.setName(NAME);
- IJVMConnector jvmConnector = (IJVMConnector)jvmConnectorDef.getInstance();
- jvmConnector.connect(500L);
- assertEquals(true, jvmConnector.isConnected());
-
- LifecycleUtil.deactivate(jvmConnector);
- LifecycleUtil.deactivate(jvmAcceptor);
- }
-
- private IJVMAcceptor createJVMAcceptor()
- {
- ExecutorService threadPool = Executors.newCachedThreadPool();
- LifecycleUtil.activate(threadPool);
-
- IBufferPool bufferPool = Net4jUtil.createBufferPool();
- LifecycleUtil.activate(bufferPool);
-
- JVMAcceptor jvmAcceptor = new JVMAcceptor();
- jvmAcceptor.setName(NAME);
- jvmAcceptor.getConfig().setBufferProvider(bufferPool);
- jvmAcceptor.getConfig().setReceiveExecutor(threadPool);
- LifecycleUtil.activate(jvmAcceptor);
-
- return jvmAcceptor;
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Andre Dietisheim - initial API and implementation
+ * Eike Stepper - maintenance
+ */
+package org.eclipse.net4j.tests.defs;
+
+import org.eclipse.net4j.Net4jUtil;
+import org.eclipse.net4j.buffer.IBufferPool;
+import org.eclipse.net4j.defs.JVMConnectorDef;
+import org.eclipse.net4j.defs.Net4jDefsFactory;
+import org.eclipse.net4j.internal.jvm.JVMAcceptor;
+import org.eclipse.net4j.jvm.IJVMAcceptor;
+import org.eclipse.net4j.jvm.IJVMConnector;
+import org.eclipse.net4j.util.defs.Net4jUtilDefsFactory;
+import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
+import org.eclipse.net4j.util.tests.AbstractOMTest;
+
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+/**
+ * @author Andre Dietisheim
+ */
+public class JVMConnectorDefImplTest extends AbstractOMTest
+{
+ private static final String NAME = "test1"; //$NON-NLS-1$
+
+ public void testIncompleteInitializationThrowsIllegalArgumentException()
+ {
+ try
+ {
+ Net4jDefsFactory.eINSTANCE.createJVMConnectorDef().getInstance();
+ fail("IllegalStateException expected!"); //$NON-NLS-1$
+ }
+ catch (IllegalStateException e)
+ {
+ }
+ }
+
+ public void testConnectorLaunchableOpensConnection()
+ {
+ IJVMAcceptor jvmAcceptor = createJVMAcceptor();
+
+ JVMConnectorDef jvmConnectorDef = Net4jDefsFactory.eINSTANCE.createJVMConnectorDef();
+
+ jvmConnectorDef.setBufferProvider(Net4jDefsFactory.eINSTANCE.createBufferPoolDef());
+ jvmConnectorDef.setExecutorService(Net4jUtilDefsFactory.eINSTANCE.createThreadPoolDef());
+ jvmConnectorDef.setName(NAME);
+ IJVMConnector jvmConnector = (IJVMConnector)jvmConnectorDef.getInstance();
+ jvmConnector.connect(500L);
+ assertEquals(true, jvmConnector.isConnected());
+
+ LifecycleUtil.deactivate(jvmConnector);
+ LifecycleUtil.deactivate(jvmAcceptor);
+ }
+
+ private IJVMAcceptor createJVMAcceptor()
+ {
+ ExecutorService threadPool = Executors.newCachedThreadPool();
+ LifecycleUtil.activate(threadPool);
+
+ IBufferPool bufferPool = Net4jUtil.createBufferPool();
+ LifecycleUtil.activate(bufferPool);
+
+ JVMAcceptor jvmAcceptor = new JVMAcceptor();
+ jvmAcceptor.setName(NAME);
+ jvmAcceptor.getConfig().setBufferProvider(bufferPool);
+ jvmAcceptor.getConfig().setReceiveExecutor(threadPool);
+ LifecycleUtil.activate(jvmAcceptor);
+
+ return jvmAcceptor;
+ }
+}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/defs/TCPAcceptorDefImplTest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/defs/TCPAcceptorDefImplTest.java
index 55ac0f6598..d19a060a0b 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/defs/TCPAcceptorDefImplTest.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/defs/TCPAcceptorDefImplTest.java
@@ -1,113 +1,113 @@
-/*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Andre Dietisheim - initial API and implementation
- * Eike Stepper - maintenance
- */
-package org.eclipse.net4j.tests.defs;
-
-import org.eclipse.net4j.defs.Net4jDefsFactory;
-import org.eclipse.net4j.defs.TCPAcceptorDef;
-import org.eclipse.net4j.internal.tcp.TCPConnector;
-import org.eclipse.net4j.tcp.ITCPAcceptor;
-import org.eclipse.net4j.util.defs.ChallengeNegotiatorDef;
-import org.eclipse.net4j.util.defs.Net4jUtilDefsFactory;
-import org.eclipse.net4j.util.defs.User;
-import org.eclipse.net4j.util.defs.UserManagerDef;
-import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
-import org.eclipse.net4j.util.tests.AbstractOMTest;
-
-/**
- * @author Andre Dietisheim
- */
-public class TCPAcceptorDefImplTest extends AbstractOMTest
-{
- private static final long TIMEOUT = 10000;
-
- private static final long DELAY = 500;
-
- private static final String HOST = "localhost"; //$NON-NLS-1$
-
- private static final int PORT = 2036;
-
- private static final String USERID = "André"; //$NON-NLS-1$
-
- private static final String PASSWORD = "aPassword"; //$NON-NLS-1$
-
- private TCPConnector tcpConnector;
-
- @Override
- protected void doSetUp() throws Exception
- {
- tcpConnector = Util.createTCPClientConnector(HOST, PORT, Util.createTCPSelector());
- }
-
- @Override
- protected void doTearDown() throws Exception
- {
- LifecycleUtil.deactivate(tcpConnector);
- }
-
- public void testAcceptorDefOpensConnection()
- {
- TCPAcceptorDef tcpAcceptorDef = createTCPAcceptorDef();
-
- ITCPAcceptor tcpAcceptor = (ITCPAcceptor)tcpAcceptorDef.getInstance();
-
- assertEquals(true, LifecycleUtil.isActive(tcpAcceptor));
-
- LifecycleUtil.activate(tcpConnector);
- tcpConnector.waitForConnection(DELAY + TIMEOUT);
- assertEquals(true, LifecycleUtil.isActive(tcpConnector));
-
- LifecycleUtil.deactivate(tcpAcceptor);
- }
-
- /**
- * Doesn't work yet: UserManager does not add its users yet
- */
- public void _testCredentialsProvider()
- {
- TCPAcceptorDef tcpAcceptorDef = createTCPAcceptorDef();
-
- User user = Net4jUtilDefsFactory.eINSTANCE.createUser();
- user.setUserID(USERID);
- user.setPassword(PASSWORD);
-
- UserManagerDef userManagerDef = Net4jUtilDefsFactory.eINSTANCE.createUserManagerDef();
- userManagerDef.getUser().add(user);
-
- ChallengeNegotiatorDef challengeNegotiatorDef = Net4jUtilDefsFactory.eINSTANCE.createChallengeNegotiatorDef();
- challengeNegotiatorDef.setRandomizer(Net4jUtilDefsFactory.eINSTANCE.createRandomizerDef());
- challengeNegotiatorDef.setUserManager(userManagerDef);
-
- tcpAcceptorDef.setNegotiator(challengeNegotiatorDef);
- ITCPAcceptor tcpAcceptor = (ITCPAcceptor)tcpAcceptorDef.getInstance();
- assertEquals(true, LifecycleUtil.isActive(tcpAcceptor));
-
- Util.addNegotiator(USERID, PASSWORD, tcpConnector);
- LifecycleUtil.activate(tcpConnector);
-
- tcpConnector.waitForConnection(DELAY + TIMEOUT);
- LifecycleUtil.deactivate(tcpConnector);
-
- Util.removeNegotiator(tcpConnector);
- LifecycleUtil.deactivate(tcpAcceptor);
- }
-
- private TCPAcceptorDef createTCPAcceptorDef()
- {
- TCPAcceptorDef tcpAcceptorDef = Net4jDefsFactory.eINSTANCE.createTCPAcceptorDef();
- tcpAcceptorDef.setHost(HOST);
- tcpAcceptorDef.setPort(PORT);
- tcpAcceptorDef.setBufferProvider(Net4jDefsFactory.eINSTANCE.createBufferPoolDef());
- tcpAcceptorDef.setExecutorService(Net4jUtilDefsFactory.eINSTANCE.createThreadPoolDef());
- tcpAcceptorDef.setTcpSelectorDef(Net4jDefsFactory.eINSTANCE.createTCPSelectorDef());
- return tcpAcceptorDef;
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Andre Dietisheim - initial API and implementation
+ * Eike Stepper - maintenance
+ */
+package org.eclipse.net4j.tests.defs;
+
+import org.eclipse.net4j.defs.Net4jDefsFactory;
+import org.eclipse.net4j.defs.TCPAcceptorDef;
+import org.eclipse.net4j.internal.tcp.TCPConnector;
+import org.eclipse.net4j.tcp.ITCPAcceptor;
+import org.eclipse.net4j.util.defs.ChallengeNegotiatorDef;
+import org.eclipse.net4j.util.defs.Net4jUtilDefsFactory;
+import org.eclipse.net4j.util.defs.User;
+import org.eclipse.net4j.util.defs.UserManagerDef;
+import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
+import org.eclipse.net4j.util.tests.AbstractOMTest;
+
+/**
+ * @author Andre Dietisheim
+ */
+public class TCPAcceptorDefImplTest extends AbstractOMTest
+{
+ private static final long TIMEOUT = 10000;
+
+ private static final long DELAY = 500;
+
+ private static final String HOST = "localhost"; //$NON-NLS-1$
+
+ private static final int PORT = 2036;
+
+ private static final String USERID = "André"; //$NON-NLS-1$
+
+ private static final String PASSWORD = "aPassword"; //$NON-NLS-1$
+
+ private TCPConnector tcpConnector;
+
+ @Override
+ protected void doSetUp() throws Exception
+ {
+ tcpConnector = Util.createTCPClientConnector(HOST, PORT, Util.createTCPSelector());
+ }
+
+ @Override
+ protected void doTearDown() throws Exception
+ {
+ LifecycleUtil.deactivate(tcpConnector);
+ }
+
+ public void testAcceptorDefOpensConnection()
+ {
+ TCPAcceptorDef tcpAcceptorDef = createTCPAcceptorDef();
+
+ ITCPAcceptor tcpAcceptor = (ITCPAcceptor)tcpAcceptorDef.getInstance();
+
+ assertEquals(true, LifecycleUtil.isActive(tcpAcceptor));
+
+ LifecycleUtil.activate(tcpConnector);
+ tcpConnector.waitForConnection(DELAY + TIMEOUT);
+ assertEquals(true, LifecycleUtil.isActive(tcpConnector));
+
+ LifecycleUtil.deactivate(tcpAcceptor);
+ }
+
+ /**
+ * Doesn't work yet: UserManager does not add its users yet
+ */
+ public void _testCredentialsProvider()
+ {
+ TCPAcceptorDef tcpAcceptorDef = createTCPAcceptorDef();
+
+ User user = Net4jUtilDefsFactory.eINSTANCE.createUser();
+ user.setUserID(USERID);
+ user.setPassword(PASSWORD);
+
+ UserManagerDef userManagerDef = Net4jUtilDefsFactory.eINSTANCE.createUserManagerDef();
+ userManagerDef.getUser().add(user);
+
+ ChallengeNegotiatorDef challengeNegotiatorDef = Net4jUtilDefsFactory.eINSTANCE.createChallengeNegotiatorDef();
+ challengeNegotiatorDef.setRandomizer(Net4jUtilDefsFactory.eINSTANCE.createRandomizerDef());
+ challengeNegotiatorDef.setUserManager(userManagerDef);
+
+ tcpAcceptorDef.setNegotiator(challengeNegotiatorDef);
+ ITCPAcceptor tcpAcceptor = (ITCPAcceptor)tcpAcceptorDef.getInstance();
+ assertEquals(true, LifecycleUtil.isActive(tcpAcceptor));
+
+ Util.addNegotiator(USERID, PASSWORD, tcpConnector);
+ LifecycleUtil.activate(tcpConnector);
+
+ tcpConnector.waitForConnection(DELAY + TIMEOUT);
+ LifecycleUtil.deactivate(tcpConnector);
+
+ Util.removeNegotiator(tcpConnector);
+ LifecycleUtil.deactivate(tcpAcceptor);
+ }
+
+ private TCPAcceptorDef createTCPAcceptorDef()
+ {
+ TCPAcceptorDef tcpAcceptorDef = Net4jDefsFactory.eINSTANCE.createTCPAcceptorDef();
+ tcpAcceptorDef.setHost(HOST);
+ tcpAcceptorDef.setPort(PORT);
+ tcpAcceptorDef.setBufferProvider(Net4jDefsFactory.eINSTANCE.createBufferPoolDef());
+ tcpAcceptorDef.setExecutorService(Net4jUtilDefsFactory.eINSTANCE.createThreadPoolDef());
+ tcpAcceptorDef.setTcpSelectorDef(Net4jDefsFactory.eINSTANCE.createTCPSelectorDef());
+ return tcpAcceptorDef;
+ }
+}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/defs/TCPConnectorDefImplTest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/defs/TCPConnectorDefImplTest.java
index c9bfbf8868..9e5f505a1e 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/defs/TCPConnectorDefImplTest.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/defs/TCPConnectorDefImplTest.java
@@ -1,126 +1,126 @@
-/*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Andre Dietisheim - initial API and implementation
- * Eike Stepper - maintenance
- */
-package org.eclipse.net4j.tests.defs;
-
-import org.eclipse.net4j.defs.Net4jDefsFactory;
-import org.eclipse.net4j.defs.TCPConnectorDef;
-import org.eclipse.net4j.internal.tcp.TCPAcceptor;
-import org.eclipse.net4j.tcp.ITCPConnector;
-import org.eclipse.net4j.tests.AbstractProtocolTest;
-import org.eclipse.net4j.util.defs.Net4jUtilDefsFactory;
-import org.eclipse.net4j.util.defs.PasswordCredentialsProviderDef;
-import org.eclipse.net4j.util.defs.ResponseNegotiatorDef;
-import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
-
-/**
- * @author Andre Dietisheim
- */
-public class TCPConnectorDefImplTest extends AbstractProtocolTest
-{
- private static final long DELAY = 500l;
-
- private static final int PORT = 2036;
-
- private static final long TIMEOUT = 10000l;
-
- private static final String USERID = "André"; //$NON-NLS-1$
-
- private static final String PASSWORD = "aPassword"; //$NON-NLS-1$
-
- private TCPAcceptor tcpAcceptor;
-
- @Override
- protected void doSetUp() throws Exception
- {
- tcpAcceptor = Util.createTCPAcceptor(HOST, PORT, DELAY);
- }
-
- @Override
- protected void doTearDown() throws Exception
- {
- LifecycleUtil.deactivate(tcpAcceptor);
- }
-
- public void testConnectorDefOpensConnection()
- {
- TCPConnectorDef tcpConnectorDef = Net4jDefsFactory.eINSTANCE.createTCPConnectorDef();
-
- tcpConnectorDef.setHost(HOST);
- tcpConnectorDef.setPort(PORT);
- tcpConnectorDef.setBufferProvider(Net4jDefsFactory.eINSTANCE.createBufferPoolDef());
- tcpConnectorDef.setExecutorService(Net4jUtilDefsFactory.eINSTANCE.createThreadPoolDef());
- tcpConnectorDef.setTcpSelectorDef(Net4jDefsFactory.eINSTANCE.createTCPSelectorDef());
-
- ITCPConnector tcpConnector = (ITCPConnector)tcpConnectorDef.getInstance();
-
- tcpConnector.waitForConnection(DELAY + TIMEOUT);
- assertEquals(true, LifecycleUtil.isActive(tcpConnector));
-
- LifecycleUtil.deactivate(tcpConnector);
- }
-
- public void testNewInstanceWhenTouched()
- {
- TCPConnectorDef tcpConnectorDef = Net4jDefsFactory.eINSTANCE.createTCPConnectorDef();
-
- tcpConnectorDef.setHost(HOST);
- tcpConnectorDef.setPort(PORT);
- tcpConnectorDef.setBufferProvider(Net4jDefsFactory.eINSTANCE.createBufferPoolDef());
- tcpConnectorDef.setExecutorService(Net4jUtilDefsFactory.eINSTANCE.createThreadPoolDef());
- tcpConnectorDef.setTcpSelectorDef(Net4jDefsFactory.eINSTANCE.createTCPSelectorDef());
-
- ITCPConnector thisTcpConnector = (ITCPConnector)tcpConnectorDef.getInstance();
- tcpConnectorDef.setPort(PORT + 1);
-
- assertEquals(true, tcpConnectorDef.isTouched());
-
- ITCPConnector thatTcpConnector = (ITCPConnector)tcpConnectorDef.getInstance();
-
- assertEquals(true, !LifecycleUtil.isActive(thisTcpConnector));
- assertEquals(true, !tcpConnectorDef.isTouched());
- assertEquals(true, thisTcpConnector != thatTcpConnector);
-
- LifecycleUtil.deactivate(thisTcpConnector);
- LifecycleUtil.deactivate(thatTcpConnector);
- }
-
- public void testCredentialsProvider()
- {
- Util.addNegotiator(USERID, PASSWORD, tcpAcceptor);
-
- TCPConnectorDef tcpConnectorDef = Net4jDefsFactory.eINSTANCE.createTCPConnectorDef();
-
- tcpConnectorDef.setHost(HOST);
- tcpConnectorDef.setPort(PORT);
- tcpConnectorDef.setBufferProvider(Net4jDefsFactory.eINSTANCE.createBufferPoolDef());
- tcpConnectorDef.setExecutorService(Net4jUtilDefsFactory.eINSTANCE.createThreadPoolDef());
- tcpConnectorDef.setTcpSelectorDef(Net4jDefsFactory.eINSTANCE.createTCPSelectorDef());
-
- PasswordCredentialsProviderDef credentialsProviderDef = Net4jUtilDefsFactory.eINSTANCE
- .createPasswordCredentialsProviderDef();
- credentialsProviderDef.setUserID(USERID);
- credentialsProviderDef.setPassword(PASSWORD);
-
- ResponseNegotiatorDef negotiatorDef = Net4jUtilDefsFactory.eINSTANCE.createResponseNegotiatorDef();
- negotiatorDef.setCredentialsProvider(credentialsProviderDef);
- tcpConnectorDef.setNegotiator(negotiatorDef);
-
- ITCPConnector tcpConnector = (ITCPConnector)tcpConnectorDef.getInstance();
-
- tcpConnector.waitForConnection(DELAY + TIMEOUT);
- assertEquals(true, LifecycleUtil.isActive(tcpConnector));
-
- LifecycleUtil.deactivate(tcpConnector);
-
- Util.removeNegotiator(tcpAcceptor);
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Andre Dietisheim - initial API and implementation
+ * Eike Stepper - maintenance
+ */
+package org.eclipse.net4j.tests.defs;
+
+import org.eclipse.net4j.defs.Net4jDefsFactory;
+import org.eclipse.net4j.defs.TCPConnectorDef;
+import org.eclipse.net4j.internal.tcp.TCPAcceptor;
+import org.eclipse.net4j.tcp.ITCPConnector;
+import org.eclipse.net4j.tests.AbstractProtocolTest;
+import org.eclipse.net4j.util.defs.Net4jUtilDefsFactory;
+import org.eclipse.net4j.util.defs.PasswordCredentialsProviderDef;
+import org.eclipse.net4j.util.defs.ResponseNegotiatorDef;
+import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
+
+/**
+ * @author Andre Dietisheim
+ */
+public class TCPConnectorDefImplTest extends AbstractProtocolTest
+{
+ private static final long DELAY = 500l;
+
+ private static final int PORT = 2036;
+
+ private static final long TIMEOUT = 10000l;
+
+ private static final String USERID = "André"; //$NON-NLS-1$
+
+ private static final String PASSWORD = "aPassword"; //$NON-NLS-1$
+
+ private TCPAcceptor tcpAcceptor;
+
+ @Override
+ protected void doSetUp() throws Exception
+ {
+ tcpAcceptor = Util.createTCPAcceptor(HOST, PORT, DELAY);
+ }
+
+ @Override
+ protected void doTearDown() throws Exception
+ {
+ LifecycleUtil.deactivate(tcpAcceptor);
+ }
+
+ public void testConnectorDefOpensConnection()
+ {
+ TCPConnectorDef tcpConnectorDef = Net4jDefsFactory.eINSTANCE.createTCPConnectorDef();
+
+ tcpConnectorDef.setHost(HOST);
+ tcpConnectorDef.setPort(PORT);
+ tcpConnectorDef.setBufferProvider(Net4jDefsFactory.eINSTANCE.createBufferPoolDef());
+ tcpConnectorDef.setExecutorService(Net4jUtilDefsFactory.eINSTANCE.createThreadPoolDef());
+ tcpConnectorDef.setTcpSelectorDef(Net4jDefsFactory.eINSTANCE.createTCPSelectorDef());
+
+ ITCPConnector tcpConnector = (ITCPConnector)tcpConnectorDef.getInstance();
+
+ tcpConnector.waitForConnection(DELAY + TIMEOUT);
+ assertEquals(true, LifecycleUtil.isActive(tcpConnector));
+
+ LifecycleUtil.deactivate(tcpConnector);
+ }
+
+ public void testNewInstanceWhenTouched()
+ {
+ TCPConnectorDef tcpConnectorDef = Net4jDefsFactory.eINSTANCE.createTCPConnectorDef();
+
+ tcpConnectorDef.setHost(HOST);
+ tcpConnectorDef.setPort(PORT);
+ tcpConnectorDef.setBufferProvider(Net4jDefsFactory.eINSTANCE.createBufferPoolDef());
+ tcpConnectorDef.setExecutorService(Net4jUtilDefsFactory.eINSTANCE.createThreadPoolDef());
+ tcpConnectorDef.setTcpSelectorDef(Net4jDefsFactory.eINSTANCE.createTCPSelectorDef());
+
+ ITCPConnector thisTcpConnector = (ITCPConnector)tcpConnectorDef.getInstance();
+ tcpConnectorDef.setPort(PORT + 1);
+
+ assertEquals(true, tcpConnectorDef.isTouched());
+
+ ITCPConnector thatTcpConnector = (ITCPConnector)tcpConnectorDef.getInstance();
+
+ assertEquals(true, !LifecycleUtil.isActive(thisTcpConnector));
+ assertEquals(true, !tcpConnectorDef.isTouched());
+ assertEquals(true, thisTcpConnector != thatTcpConnector);
+
+ LifecycleUtil.deactivate(thisTcpConnector);
+ LifecycleUtil.deactivate(thatTcpConnector);
+ }
+
+ public void testCredentialsProvider()
+ {
+ Util.addNegotiator(USERID, PASSWORD, tcpAcceptor);
+
+ TCPConnectorDef tcpConnectorDef = Net4jDefsFactory.eINSTANCE.createTCPConnectorDef();
+
+ tcpConnectorDef.setHost(HOST);
+ tcpConnectorDef.setPort(PORT);
+ tcpConnectorDef.setBufferProvider(Net4jDefsFactory.eINSTANCE.createBufferPoolDef());
+ tcpConnectorDef.setExecutorService(Net4jUtilDefsFactory.eINSTANCE.createThreadPoolDef());
+ tcpConnectorDef.setTcpSelectorDef(Net4jDefsFactory.eINSTANCE.createTCPSelectorDef());
+
+ PasswordCredentialsProviderDef credentialsProviderDef = Net4jUtilDefsFactory.eINSTANCE
+ .createPasswordCredentialsProviderDef();
+ credentialsProviderDef.setUserID(USERID);
+ credentialsProviderDef.setPassword(PASSWORD);
+
+ ResponseNegotiatorDef negotiatorDef = Net4jUtilDefsFactory.eINSTANCE.createResponseNegotiatorDef();
+ negotiatorDef.setCredentialsProvider(credentialsProviderDef);
+ tcpConnectorDef.setNegotiator(negotiatorDef);
+
+ ITCPConnector tcpConnector = (ITCPConnector)tcpConnectorDef.getInstance();
+
+ tcpConnector.waitForConnection(DELAY + TIMEOUT);
+ assertEquals(true, LifecycleUtil.isActive(tcpConnector));
+
+ LifecycleUtil.deactivate(tcpConnector);
+
+ Util.removeNegotiator(tcpAcceptor);
+ }
+}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/defs/Util.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/defs/Util.java
index a4c4cfb1f1..3c7a87bc6b 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/defs/Util.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/defs/Util.java
@@ -1,138 +1,138 @@
-/*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- */
-package org.eclipse.net4j.tests.defs;
-
-import org.eclipse.net4j.Net4jUtil;
-import org.eclipse.net4j.buffer.IBufferPool;
-import org.eclipse.net4j.internal.tcp.TCPAcceptor;
-import org.eclipse.net4j.internal.tcp.TCPClientConnector;
-import org.eclipse.net4j.internal.tcp.TCPConnector;
-import org.eclipse.net4j.internal.tcp.TCPSelector;
-import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
-import org.eclipse.net4j.util.security.ChallengeNegotiator;
-import org.eclipse.net4j.util.security.INegotiator;
-import org.eclipse.net4j.util.security.IRandomizer;
-import org.eclipse.net4j.util.security.PasswordCredentials;
-import org.eclipse.net4j.util.security.PasswordCredentialsProvider;
-import org.eclipse.net4j.util.security.Randomizer;
-import org.eclipse.net4j.util.security.ResponseNegotiator;
-import org.eclipse.net4j.util.security.UserManager;
-
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-
-/**
- * @author Eike Stepper
- */
-class Util
-{
- public static TCPAcceptor createTCPAcceptor(String host, int port, long timeout)
- {
- TCPAcceptor acceptor = new TCPAcceptor();
- acceptor.setStartSynchronously(true);
- acceptor.setSynchronousStartTimeout(timeout);
- acceptor.getConfig().setBufferProvider(createBufferPool());
- acceptor.getConfig().setReceiveExecutor(createThreadPool());
- acceptor.setSelector(createTCPSelector());
- acceptor.setAddress(host);
- acceptor.setPort(port);
-
- LifecycleUtil.activate(acceptor);
-
- return acceptor;
- }
-
- private static IRandomizer createRandomizer()
- {
- Randomizer randomizer = new Randomizer();
- LifecycleUtil.activate(randomizer);
-
- return randomizer;
- }
-
- public static void addNegotiator(String userId, String password, TCPAcceptor tcpAcceptor)
- {
- UserManager userManager = new UserManager();
- LifecycleUtil.activate(userManager);
- userManager.addUser(userId, password.toCharArray());
-
- ChallengeNegotiator challengeNegotiator = new ChallengeNegotiator();
- challengeNegotiator.setRandomizer(createRandomizer());
- challengeNegotiator.setUserManager(userManager);
- LifecycleUtil.activate(challengeNegotiator);
-
- tcpAcceptor.getConfig().setNegotiator(challengeNegotiator);
- }
-
- public static void removeNegotiator(TCPAcceptor tcpAcceptor)
- {
- INegotiator negotiator = tcpAcceptor.getConfig().getNegotiator();
- tcpAcceptor.getConfig().setNegotiator(null);
- LifecycleUtil.deactivate(negotiator);
- }
-
- public static TCPConnector createTCPClientConnector(String host, int port, TCPSelector tcpSelector)
- {
- TCPClientConnector tcpConnector = new TCPClientConnector();
- tcpConnector.getConfig().setBufferProvider(createBufferPool());
- tcpConnector.getConfig().setReceiveExecutor(createThreadPool());
- tcpConnector.setSelector(tcpSelector);
- tcpConnector.setHost(host);
- tcpConnector.setPort(port);
-
- return tcpConnector;
- }
-
- public static void addNegotiator(String userId, String password, TCPConnector tcpConnector)
- {
- PasswordCredentials passwordCredentials = new PasswordCredentials(userId, password.toCharArray());
- PasswordCredentialsProvider credentialsProvider = new PasswordCredentialsProvider(passwordCredentials);
- LifecycleUtil.activate(credentialsProvider);
-
- tcpConnector.getConfig().setNegotiator(createResponseNegotiator(credentialsProvider));
- }
-
- public static ResponseNegotiator createResponseNegotiator(PasswordCredentialsProvider credentialsProvider)
- {
- ResponseNegotiator responseNegotiator = new ResponseNegotiator();
- responseNegotiator.setCredentialsProvider(credentialsProvider);
- LifecycleUtil.activate(responseNegotiator);
- return responseNegotiator;
- }
-
- public static void removeNegotiator(TCPConnector tcpConnector)
- {
- INegotiator negotiator = tcpConnector.getConfig().getNegotiator();
- tcpConnector.setNegotiator(null);
- LifecycleUtil.deactivate(negotiator);
- }
-
- public static TCPSelector createTCPSelector()
- {
- TCPSelector selector = new TCPSelector();
- LifecycleUtil.activate(selector);
- return selector;
- }
-
- public static IBufferPool createBufferPool()
- {
- IBufferPool bufferPool = Net4jUtil.createBufferPool();
- LifecycleUtil.activate(bufferPool);
- return bufferPool;
- }
-
- public static ExecutorService createThreadPool()
- {
- ExecutorService threadPool = Executors.newCachedThreadPool();
- LifecycleUtil.activate(threadPool);
- return threadPool;
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.tests.defs;
+
+import org.eclipse.net4j.Net4jUtil;
+import org.eclipse.net4j.buffer.IBufferPool;
+import org.eclipse.net4j.internal.tcp.TCPAcceptor;
+import org.eclipse.net4j.internal.tcp.TCPClientConnector;
+import org.eclipse.net4j.internal.tcp.TCPConnector;
+import org.eclipse.net4j.internal.tcp.TCPSelector;
+import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
+import org.eclipse.net4j.util.security.ChallengeNegotiator;
+import org.eclipse.net4j.util.security.INegotiator;
+import org.eclipse.net4j.util.security.IRandomizer;
+import org.eclipse.net4j.util.security.PasswordCredentials;
+import org.eclipse.net4j.util.security.PasswordCredentialsProvider;
+import org.eclipse.net4j.util.security.Randomizer;
+import org.eclipse.net4j.util.security.ResponseNegotiator;
+import org.eclipse.net4j.util.security.UserManager;
+
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+
+/**
+ * @author Eike Stepper
+ */
+class Util
+{
+ public static TCPAcceptor createTCPAcceptor(String host, int port, long timeout)
+ {
+ TCPAcceptor acceptor = new TCPAcceptor();
+ acceptor.setStartSynchronously(true);
+ acceptor.setSynchronousStartTimeout(timeout);
+ acceptor.getConfig().setBufferProvider(createBufferPool());
+ acceptor.getConfig().setReceiveExecutor(createThreadPool());
+ acceptor.setSelector(createTCPSelector());
+ acceptor.setAddress(host);
+ acceptor.setPort(port);
+
+ LifecycleUtil.activate(acceptor);
+
+ return acceptor;
+ }
+
+ private static IRandomizer createRandomizer()
+ {
+ Randomizer randomizer = new Randomizer();
+ LifecycleUtil.activate(randomizer);
+
+ return randomizer;
+ }
+
+ public static void addNegotiator(String userId, String password, TCPAcceptor tcpAcceptor)
+ {
+ UserManager userManager = new UserManager();
+ LifecycleUtil.activate(userManager);
+ userManager.addUser(userId, password.toCharArray());
+
+ ChallengeNegotiator challengeNegotiator = new ChallengeNegotiator();
+ challengeNegotiator.setRandomizer(createRandomizer());
+ challengeNegotiator.setUserManager(userManager);
+ LifecycleUtil.activate(challengeNegotiator);
+
+ tcpAcceptor.getConfig().setNegotiator(challengeNegotiator);
+ }
+
+ public static void removeNegotiator(TCPAcceptor tcpAcceptor)
+ {
+ INegotiator negotiator = tcpAcceptor.getConfig().getNegotiator();
+ tcpAcceptor.getConfig().setNegotiator(null);
+ LifecycleUtil.deactivate(negotiator);
+ }
+
+ public static TCPConnector createTCPClientConnector(String host, int port, TCPSelector tcpSelector)
+ {
+ TCPClientConnector tcpConnector = new TCPClientConnector();
+ tcpConnector.getConfig().setBufferProvider(createBufferPool());
+ tcpConnector.getConfig().setReceiveExecutor(createThreadPool());
+ tcpConnector.setSelector(tcpSelector);
+ tcpConnector.setHost(host);
+ tcpConnector.setPort(port);
+
+ return tcpConnector;
+ }
+
+ public static void addNegotiator(String userId, String password, TCPConnector tcpConnector)
+ {
+ PasswordCredentials passwordCredentials = new PasswordCredentials(userId, password.toCharArray());
+ PasswordCredentialsProvider credentialsProvider = new PasswordCredentialsProvider(passwordCredentials);
+ LifecycleUtil.activate(credentialsProvider);
+
+ tcpConnector.getConfig().setNegotiator(createResponseNegotiator(credentialsProvider));
+ }
+
+ public static ResponseNegotiator createResponseNegotiator(PasswordCredentialsProvider credentialsProvider)
+ {
+ ResponseNegotiator responseNegotiator = new ResponseNegotiator();
+ responseNegotiator.setCredentialsProvider(credentialsProvider);
+ LifecycleUtil.activate(responseNegotiator);
+ return responseNegotiator;
+ }
+
+ public static void removeNegotiator(TCPConnector tcpConnector)
+ {
+ INegotiator negotiator = tcpConnector.getConfig().getNegotiator();
+ tcpConnector.setNegotiator(null);
+ LifecycleUtil.deactivate(negotiator);
+ }
+
+ public static TCPSelector createTCPSelector()
+ {
+ TCPSelector selector = new TCPSelector();
+ LifecycleUtil.activate(selector);
+ return selector;
+ }
+
+ public static IBufferPool createBufferPool()
+ {
+ IBufferPool bufferPool = Net4jUtil.createBufferPool();
+ LifecycleUtil.activate(bufferPool);
+ return bufferPool;
+ }
+
+ public static ExecutorService createThreadPool()
+ {
+ ExecutorService threadPool = Executors.newCachedThreadPool();
+ LifecycleUtil.activate(threadPool);
+ return threadPool;
+ }
+}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/ArrayIndication.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/ArrayIndication.java
index 5bb329c483..443060356f 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/ArrayIndication.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/ArrayIndication.java
@@ -1,40 +1,40 @@
-/*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- */
-package org.eclipse.net4j.tests.signal;
-
-import org.eclipse.net4j.signal.IndicationWithResponse;
-import org.eclipse.net4j.util.io.ExtendedDataInputStream;
-import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
-
-/**
- * @author Eike Stepper
- */
-public class ArrayIndication extends IndicationWithResponse
-{
- private byte[] data;
-
- public ArrayIndication(TestSignalProtocol protocol)
- {
- super(protocol, TestSignalProtocol.SIGNAL_ARRAY);
- }
-
- @Override
- protected void indicating(ExtendedDataInputStream in) throws Exception
- {
- data = in.readByteArray();
- }
-
- @Override
- protected void responding(ExtendedDataOutputStream out) throws Exception
- {
- out.writeByteArray(data);
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.tests.signal;
+
+import org.eclipse.net4j.signal.IndicationWithResponse;
+import org.eclipse.net4j.util.io.ExtendedDataInputStream;
+import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
+
+/**
+ * @author Eike Stepper
+ */
+public class ArrayIndication extends IndicationWithResponse
+{
+ private byte[] data;
+
+ public ArrayIndication(TestSignalProtocol protocol)
+ {
+ super(protocol, TestSignalProtocol.SIGNAL_ARRAY);
+ }
+
+ @Override
+ protected void indicating(ExtendedDataInputStream in) throws Exception
+ {
+ data = in.readByteArray();
+ }
+
+ @Override
+ protected void responding(ExtendedDataOutputStream out) throws Exception
+ {
+ out.writeByteArray(data);
+ }
+}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/ArrayRequest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/ArrayRequest.java
index b667dbd9e5..240c5e2e90 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/ArrayRequest.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/ArrayRequest.java
@@ -1,42 +1,42 @@
-/*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- */
-package org.eclipse.net4j.tests.signal;
-
-import org.eclipse.net4j.signal.RequestWithConfirmation;
-import org.eclipse.net4j.signal.SignalProtocol;
-import org.eclipse.net4j.util.io.ExtendedDataInputStream;
-import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
-
-/**
- * @author Eike Stepper
- */
-public class ArrayRequest extends RequestWithConfirmation<byte[]>
-{
- private byte[] data;
-
- public ArrayRequest(SignalProtocol<?> protocol, byte[] data)
- {
- super(protocol, TestSignalProtocol.SIGNAL_ARRAY);
- this.data = data;
- }
-
- @Override
- protected void requesting(ExtendedDataOutputStream out) throws Exception
- {
- out.writeByteArray(data);
- }
-
- @Override
- protected byte[] confirming(ExtendedDataInputStream in) throws Exception
- {
- return in.readByteArray();
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.tests.signal;
+
+import org.eclipse.net4j.signal.RequestWithConfirmation;
+import org.eclipse.net4j.signal.SignalProtocol;
+import org.eclipse.net4j.util.io.ExtendedDataInputStream;
+import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
+
+/**
+ * @author Eike Stepper
+ */
+public class ArrayRequest extends RequestWithConfirmation<byte[]>
+{
+ private byte[] data;
+
+ public ArrayRequest(SignalProtocol<?> protocol, byte[] data)
+ {
+ super(protocol, TestSignalProtocol.SIGNAL_ARRAY);
+ this.data = data;
+ }
+
+ @Override
+ protected void requesting(ExtendedDataOutputStream out) throws Exception
+ {
+ out.writeByteArray(data);
+ }
+
+ @Override
+ protected byte[] confirming(ExtendedDataInputStream in) throws Exception
+ {
+ return in.readByteArray();
+ }
+}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/AsyncIndication.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/AsyncIndication.java
index ce1af89f08..4e42fe7ae0 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/AsyncIndication.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/AsyncIndication.java
@@ -1,39 +1,39 @@
-/*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- */
-package org.eclipse.net4j.tests.signal;
-
-import org.eclipse.net4j.signal.Indication;
-import org.eclipse.net4j.signal.SignalProtocol;
-import org.eclipse.net4j.util.io.ExtendedDataInputStream;
-
-/**
- * @author Eike Stepper
- */
-public class AsyncIndication extends Indication
-{
- private String data;
-
- public AsyncIndication(SignalProtocol<?> protocol)
- {
- super(protocol, TestSignalProtocol.SIGNAL_ASYNC);
- }
-
- public String getData()
- {
- return data;
- }
-
- @Override
- protected void indicating(ExtendedDataInputStream in) throws Exception
- {
- data = in.readString();
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.tests.signal;
+
+import org.eclipse.net4j.signal.Indication;
+import org.eclipse.net4j.signal.SignalProtocol;
+import org.eclipse.net4j.util.io.ExtendedDataInputStream;
+
+/**
+ * @author Eike Stepper
+ */
+public class AsyncIndication extends Indication
+{
+ private String data;
+
+ public AsyncIndication(SignalProtocol<?> protocol)
+ {
+ super(protocol, TestSignalProtocol.SIGNAL_ASYNC);
+ }
+
+ public String getData()
+ {
+ return data;
+ }
+
+ @Override
+ protected void indicating(ExtendedDataInputStream in) throws Exception
+ {
+ data = in.readString();
+ }
+}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/AsyncRequest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/AsyncRequest.java
index 26e4e84629..0f950f50be 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/AsyncRequest.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/AsyncRequest.java
@@ -1,35 +1,35 @@
-/*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- */
-package org.eclipse.net4j.tests.signal;
-
-import org.eclipse.net4j.signal.Request;
-import org.eclipse.net4j.signal.SignalProtocol;
-import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
-
-/**
- * @author Eike Stepper
- */
-public class AsyncRequest extends Request
-{
- private String data;
-
- public AsyncRequest(SignalProtocol<?> protocol, String data)
- {
- super(protocol, TestSignalProtocol.SIGNAL_ASYNC);
- this.data = data;
- }
-
- @Override
- protected void requesting(ExtendedDataOutputStream out) throws Exception
- {
- out.writeString(data);
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.tests.signal;
+
+import org.eclipse.net4j.signal.Request;
+import org.eclipse.net4j.signal.SignalProtocol;
+import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
+
+/**
+ * @author Eike Stepper
+ */
+public class AsyncRequest extends Request
+{
+ private String data;
+
+ public AsyncRequest(SignalProtocol<?> protocol, String data)
+ {
+ super(protocol, TestSignalProtocol.SIGNAL_ASYNC);
+ this.data = data;
+ }
+
+ @Override
+ protected void requesting(ExtendedDataOutputStream out) throws Exception
+ {
+ out.writeString(data);
+ }
+}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/ExceptionIndication.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/ExceptionIndication.java
index 5decba0a9d..debe1026c1 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/ExceptionIndication.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/ExceptionIndication.java
@@ -1,57 +1,57 @@
-/*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- */
-package org.eclipse.net4j.tests.signal;
-
-import org.eclipse.net4j.signal.IndicationWithResponse;
-import org.eclipse.net4j.util.io.ExtendedDataInputStream;
-import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
-
-/**
- * @author Eike Stepper
- */
-public class ExceptionIndication extends IndicationWithResponse
-{
- private int phase;
-
- private boolean ioProblem;
-
- public ExceptionIndication(TestSignalProtocol protocol)
- {
- super(protocol, TestSignalProtocol.SIGNAL_EXCEPTION);
- }
-
- public int getPhase()
- {
- return phase;
- }
-
- @Override
- protected void indicating(ExtendedDataInputStream in) throws Exception
- {
- phase = in.readInt();
- ioProblem = in.readBoolean();
- if (phase == 2)
- {
- ((TestSignalProtocol)getProtocol()).throwException(ioProblem);
- }
- }
-
- @Override
- protected void responding(ExtendedDataOutputStream out) throws Exception
- {
- if (phase == 3)
- {
- ((TestSignalProtocol)getProtocol()).throwException(ioProblem);
- }
-
- out.writeBoolean(true);
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.tests.signal;
+
+import org.eclipse.net4j.signal.IndicationWithResponse;
+import org.eclipse.net4j.util.io.ExtendedDataInputStream;
+import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
+
+/**
+ * @author Eike Stepper
+ */
+public class ExceptionIndication extends IndicationWithResponse
+{
+ private int phase;
+
+ private boolean ioProblem;
+
+ public ExceptionIndication(TestSignalProtocol protocol)
+ {
+ super(protocol, TestSignalProtocol.SIGNAL_EXCEPTION);
+ }
+
+ public int getPhase()
+ {
+ return phase;
+ }
+
+ @Override
+ protected void indicating(ExtendedDataInputStream in) throws Exception
+ {
+ phase = in.readInt();
+ ioProblem = in.readBoolean();
+ if (phase == 2)
+ {
+ ((TestSignalProtocol)getProtocol()).throwException(ioProblem);
+ }
+ }
+
+ @Override
+ protected void responding(ExtendedDataOutputStream out) throws Exception
+ {
+ if (phase == 3)
+ {
+ ((TestSignalProtocol)getProtocol()).throwException(ioProblem);
+ }
+
+ out.writeBoolean(true);
+ }
+}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/ExceptionRequest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/ExceptionRequest.java
index 70b3b15045..ef4a5031fe 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/ExceptionRequest.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/ExceptionRequest.java
@@ -1,54 +1,54 @@
-/*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- */
-package org.eclipse.net4j.tests.signal;
-
-import org.eclipse.net4j.signal.RequestWithConfirmation;
-import org.eclipse.net4j.util.io.ExtendedDataInputStream;
-import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
-
-/**
- * @author Eike Stepper
- */
-public class ExceptionRequest extends RequestWithConfirmation<Boolean>
-{
- private int phase;
-
- private boolean ioProblem;
-
- public ExceptionRequest(TestSignalProtocol protocol, int phase, boolean ioProblem)
- {
- super(protocol, TestSignalProtocol.SIGNAL_EXCEPTION);
- this.phase = phase;
- this.ioProblem = ioProblem;
- }
-
- @Override
- protected void requesting(ExtendedDataOutputStream out) throws Exception
- {
- out.writeInt(phase);
- out.writeBoolean(ioProblem);
- if (phase == 1)
- {
- ((TestSignalProtocol)getProtocol()).throwException(ioProblem);
- }
- }
-
- @Override
- protected Boolean confirming(ExtendedDataInputStream in) throws Exception
- {
- if (phase == 4)
- {
- ((TestSignalProtocol)getProtocol()).throwException(ioProblem);
- }
-
- return in.readBoolean();
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.tests.signal;
+
+import org.eclipse.net4j.signal.RequestWithConfirmation;
+import org.eclipse.net4j.util.io.ExtendedDataInputStream;
+import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
+
+/**
+ * @author Eike Stepper
+ */
+public class ExceptionRequest extends RequestWithConfirmation<Boolean>
+{
+ private int phase;
+
+ private boolean ioProblem;
+
+ public ExceptionRequest(TestSignalProtocol protocol, int phase, boolean ioProblem)
+ {
+ super(protocol, TestSignalProtocol.SIGNAL_EXCEPTION);
+ this.phase = phase;
+ this.ioProblem = ioProblem;
+ }
+
+ @Override
+ protected void requesting(ExtendedDataOutputStream out) throws Exception
+ {
+ out.writeInt(phase);
+ out.writeBoolean(ioProblem);
+ if (phase == 1)
+ {
+ ((TestSignalProtocol)getProtocol()).throwException(ioProblem);
+ }
+ }
+
+ @Override
+ protected Boolean confirming(ExtendedDataInputStream in) throws Exception
+ {
+ if (phase == 4)
+ {
+ ((TestSignalProtocol)getProtocol()).throwException(ioProblem);
+ }
+
+ return in.readBoolean();
+ }
+}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/IntFailIndication.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/IntFailIndication.java
index ecec61e1fb..04f668168a 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/IntFailIndication.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/IntFailIndication.java
@@ -1,45 +1,45 @@
-/*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- */
-package org.eclipse.net4j.tests.signal;
-
-import org.eclipse.net4j.signal.IndicationWithResponse;
-import org.eclipse.net4j.util.io.ExtendedDataInputStream;
-import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
-
-/**
- * @author Eike Stepper
- */
-public class IntFailIndication extends IndicationWithResponse
-{
- private int data;
-
- public IntFailIndication(TestSignalProtocol protocol)
- {
- super(protocol, TestSignalProtocol.SIGNAL_INT_FAIL);
- }
-
- public int getData()
- {
- return data;
- }
-
- @Override
- protected void indicating(ExtendedDataInputStream in) throws Exception
- {
- data = in.readInt();
- }
-
- @Override
- protected void responding(ExtendedDataOutputStream out) throws Exception
- {
- getProtocol().deactivate();
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.tests.signal;
+
+import org.eclipse.net4j.signal.IndicationWithResponse;
+import org.eclipse.net4j.util.io.ExtendedDataInputStream;
+import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
+
+/**
+ * @author Eike Stepper
+ */
+public class IntFailIndication extends IndicationWithResponse
+{
+ private int data;
+
+ public IntFailIndication(TestSignalProtocol protocol)
+ {
+ super(protocol, TestSignalProtocol.SIGNAL_INT_FAIL);
+ }
+
+ public int getData()
+ {
+ return data;
+ }
+
+ @Override
+ protected void indicating(ExtendedDataInputStream in) throws Exception
+ {
+ data = in.readInt();
+ }
+
+ @Override
+ protected void responding(ExtendedDataOutputStream out) throws Exception
+ {
+ getProtocol().deactivate();
+ }
+}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/IntFailRequest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/IntFailRequest.java
index bc760b2aac..4b34154254 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/IntFailRequest.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/IntFailRequest.java
@@ -1,41 +1,41 @@
-/*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- */
-package org.eclipse.net4j.tests.signal;
-
-import org.eclipse.net4j.signal.RequestWithConfirmation;
-import org.eclipse.net4j.util.io.ExtendedDataInputStream;
-import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
-
-/**
- * @author Eike Stepper
- */
-public class IntFailRequest extends RequestWithConfirmation<Integer>
-{
- private int data;
-
- public IntFailRequest(TestSignalProtocol protocol, int data)
- {
- super(protocol, TestSignalProtocol.SIGNAL_INT_FAIL);
- this.data = data;
- }
-
- @Override
- protected void requesting(ExtendedDataOutputStream out) throws Exception
- {
- out.writeInt(data);
- }
-
- @Override
- protected Integer confirming(ExtendedDataInputStream in) throws Exception
- {
- return in.readInt();
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.tests.signal;
+
+import org.eclipse.net4j.signal.RequestWithConfirmation;
+import org.eclipse.net4j.util.io.ExtendedDataInputStream;
+import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
+
+/**
+ * @author Eike Stepper
+ */
+public class IntFailRequest extends RequestWithConfirmation<Integer>
+{
+ private int data;
+
+ public IntFailRequest(TestSignalProtocol protocol, int data)
+ {
+ super(protocol, TestSignalProtocol.SIGNAL_INT_FAIL);
+ this.data = data;
+ }
+
+ @Override
+ protected void requesting(ExtendedDataOutputStream out) throws Exception
+ {
+ out.writeInt(data);
+ }
+
+ @Override
+ protected Integer confirming(ExtendedDataInputStream in) throws Exception
+ {
+ return in.readInt();
+ }
+}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/IntIndication.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/IntIndication.java
index a624062aed..67e2f7ec94 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/IntIndication.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/IntIndication.java
@@ -1,40 +1,40 @@
-/*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- */
-package org.eclipse.net4j.tests.signal;
-
-import org.eclipse.net4j.signal.IndicationWithResponse;
-import org.eclipse.net4j.util.io.ExtendedDataInputStream;
-import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
-
-/**
- * @author Eike Stepper
- */
-public class IntIndication extends IndicationWithResponse
-{
- private int data;
-
- public IntIndication(TestSignalProtocol protocol)
- {
- super(protocol, TestSignalProtocol.SIGNAL_INT);
- }
-
- @Override
- protected void indicating(ExtendedDataInputStream in) throws Exception
- {
- data = in.readInt();
- }
-
- @Override
- protected void responding(ExtendedDataOutputStream out) throws Exception
- {
- out.writeInt(data);
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.tests.signal;
+
+import org.eclipse.net4j.signal.IndicationWithResponse;
+import org.eclipse.net4j.util.io.ExtendedDataInputStream;
+import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
+
+/**
+ * @author Eike Stepper
+ */
+public class IntIndication extends IndicationWithResponse
+{
+ private int data;
+
+ public IntIndication(TestSignalProtocol protocol)
+ {
+ super(protocol, TestSignalProtocol.SIGNAL_INT);
+ }
+
+ @Override
+ protected void indicating(ExtendedDataInputStream in) throws Exception
+ {
+ data = in.readInt();
+ }
+
+ @Override
+ protected void responding(ExtendedDataOutputStream out) throws Exception
+ {
+ out.writeInt(data);
+ }
+}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/IntRequest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/IntRequest.java
index 46716c562d..70bcff63ea 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/IntRequest.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/IntRequest.java
@@ -1,41 +1,41 @@
-/*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- */
-package org.eclipse.net4j.tests.signal;
-
-import org.eclipse.net4j.signal.RequestWithConfirmation;
-import org.eclipse.net4j.util.io.ExtendedDataInputStream;
-import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
-
-/**
- * @author Eike Stepper
- */
-public class IntRequest extends RequestWithConfirmation<Integer>
-{
- private int data;
-
- public IntRequest(TestSignalProtocol protocol, int data)
- {
- super(protocol, TestSignalProtocol.SIGNAL_INT);
- this.data = data;
- }
-
- @Override
- protected void requesting(ExtendedDataOutputStream out) throws Exception
- {
- out.writeInt(data);
- }
-
- @Override
- protected Integer confirming(ExtendedDataInputStream in) throws Exception
- {
- return in.readInt();
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.tests.signal;
+
+import org.eclipse.net4j.signal.RequestWithConfirmation;
+import org.eclipse.net4j.util.io.ExtendedDataInputStream;
+import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
+
+/**
+ * @author Eike Stepper
+ */
+public class IntRequest extends RequestWithConfirmation<Integer>
+{
+ private int data;
+
+ public IntRequest(TestSignalProtocol protocol, int data)
+ {
+ super(protocol, TestSignalProtocol.SIGNAL_INT);
+ this.data = data;
+ }
+
+ @Override
+ protected void requesting(ExtendedDataOutputStream out) throws Exception
+ {
+ out.writeInt(data);
+ }
+
+ @Override
+ protected Integer confirming(ExtendedDataInputStream in) throws Exception
+ {
+ return in.readInt();
+ }
+}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/StringIndication.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/StringIndication.java
index db75395786..47846a43fb 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/StringIndication.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/StringIndication.java
@@ -1,40 +1,40 @@
-/*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- */
-package org.eclipse.net4j.tests.signal;
-
-import org.eclipse.net4j.signal.IndicationWithResponse;
-import org.eclipse.net4j.util.io.ExtendedDataInputStream;
-import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
-
-/**
- * @author Eike Stepper
- */
-public class StringIndication extends IndicationWithResponse
-{
- private String data;
-
- public StringIndication(TestSignalProtocol protocol)
- {
- super(protocol, TestSignalProtocol.SIGNAL_STRING);
- }
-
- @Override
- protected void indicating(ExtendedDataInputStream in) throws Exception
- {
- data = in.readString();
- }
-
- @Override
- protected void responding(ExtendedDataOutputStream out) throws Exception
- {
- out.writeString(data);
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.tests.signal;
+
+import org.eclipse.net4j.signal.IndicationWithResponse;
+import org.eclipse.net4j.util.io.ExtendedDataInputStream;
+import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
+
+/**
+ * @author Eike Stepper
+ */
+public class StringIndication extends IndicationWithResponse
+{
+ private String data;
+
+ public StringIndication(TestSignalProtocol protocol)
+ {
+ super(protocol, TestSignalProtocol.SIGNAL_STRING);
+ }
+
+ @Override
+ protected void indicating(ExtendedDataInputStream in) throws Exception
+ {
+ data = in.readString();
+ }
+
+ @Override
+ protected void responding(ExtendedDataOutputStream out) throws Exception
+ {
+ out.writeString(data);
+ }
+}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/StringRequest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/StringRequest.java
index 5878ae6295..0a4a95031b 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/StringRequest.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/StringRequest.java
@@ -1,42 +1,42 @@
-/*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- */
-package org.eclipse.net4j.tests.signal;
-
-import org.eclipse.net4j.signal.RequestWithConfirmation;
-import org.eclipse.net4j.signal.SignalProtocol;
-import org.eclipse.net4j.util.io.ExtendedDataInputStream;
-import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
-
-/**
- * @author Eike Stepper
- */
-public class StringRequest extends RequestWithConfirmation<String>
-{
- private String data;
-
- public StringRequest(SignalProtocol<?> protocol, String data)
- {
- super(protocol, TestSignalProtocol.SIGNAL_STRING);
- this.data = data;
- }
-
- @Override
- protected void requesting(ExtendedDataOutputStream out) throws Exception
- {
- out.writeString(data);
- }
-
- @Override
- protected String confirming(ExtendedDataInputStream in) throws Exception
- {
- return in.readString();
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.tests.signal;
+
+import org.eclipse.net4j.signal.RequestWithConfirmation;
+import org.eclipse.net4j.signal.SignalProtocol;
+import org.eclipse.net4j.util.io.ExtendedDataInputStream;
+import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
+
+/**
+ * @author Eike Stepper
+ */
+public class StringRequest extends RequestWithConfirmation<String>
+{
+ private String data;
+
+ public StringRequest(SignalProtocol<?> protocol, String data)
+ {
+ super(protocol, TestSignalProtocol.SIGNAL_STRING);
+ this.data = data;
+ }
+
+ @Override
+ protected void requesting(ExtendedDataOutputStream out) throws Exception
+ {
+ out.writeString(data);
+ }
+
+ @Override
+ protected String confirming(ExtendedDataInputStream in) throws Exception
+ {
+ return in.readString();
+ }
+}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/TestSignalProtocol.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/TestSignalProtocol.java
index 60c3611168..6b01d7c611 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/TestSignalProtocol.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/tests/signal/TestSignalProtocol.java
@@ -1,120 +1,120 @@
-/*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- */
-package org.eclipse.net4j.tests.signal;
-
-import org.eclipse.net4j.connector.IConnector;
-import org.eclipse.net4j.signal.SignalProtocol;
-import org.eclipse.net4j.signal.SignalReactor;
-import org.eclipse.net4j.util.factory.ProductCreationException;
-
-import org.eclipse.spi.net4j.ServerProtocolFactory;
-
-import java.io.IOException;
-import java.rmi.AlreadyBoundException;
-
-/**
- * @author Eike Stepper
- */
-public class TestSignalProtocol extends SignalProtocol<Object>
-{
- public static final String PROTOCOL_NAME = "signal.protocol"; //$NON-NLS-1$
-
- public static final short SIGNAL_INT = 1;
-
- public static final short SIGNAL_INT_FAIL = 2;
-
- public static final short SIGNAL_ARRAY = 3;
-
- public static final short SIGNAL_STRING = 4;
-
- public static final short SIGNAL_ASYNC = 5;
-
- public static final short SIGNAL_EXCEPTION = 6;
-
- public static final String SIMULATED_EXCEPTION = "Simulated exception"; //$NON-NLS-1$
-
- public TestSignalProtocol(IConnector connector)
- {
- this();
- open(connector);
- }
-
- public TestSignalProtocol()
- {
- super(PROTOCOL_NAME);
- }
-
- @Override
- protected SignalReactor createSignalReactor(short signalID)
- {
- switch (signalID)
- {
- case SIGNAL_INT:
- return new IntIndication(this);
-
- case SIGNAL_INT_FAIL:
- return new IntFailIndication(this);
-
- case SIGNAL_ARRAY:
- return new ArrayIndication(this);
-
- case SIGNAL_STRING:
- return new StringIndication(this);
-
- case SIGNAL_ASYNC:
- return new AsyncIndication(this);
-
- case SIGNAL_EXCEPTION:
- return new ExceptionIndication(this);
-
- default:
- return super.createSignalReactor(signalID);
- }
- }
-
- public void throwException(boolean ioProblem) throws Exception
- {
- if (ioProblem)
- {
- throw new IOException(SIMULATED_EXCEPTION);
- }
-
- try
- {
- throwNestedException();
- }
- catch (Exception ex)
- {
- throw new ClassNotFoundException(SIMULATED_EXCEPTION, ex);
- }
- }
-
- public void throwNestedException() throws Exception
- {
- throw new AlreadyBoundException(SIMULATED_EXCEPTION);
- }
-
- /**
- * @author Eike Stepper
- */
- public static class Factory extends ServerProtocolFactory
- {
- public Factory()
- {
- super(PROTOCOL_NAME);
- }
-
- public TestSignalProtocol create(String description) throws ProductCreationException
- {
- return new TestSignalProtocol();
- }
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.tests.signal;
+
+import org.eclipse.net4j.connector.IConnector;
+import org.eclipse.net4j.signal.SignalProtocol;
+import org.eclipse.net4j.signal.SignalReactor;
+import org.eclipse.net4j.util.factory.ProductCreationException;
+
+import org.eclipse.spi.net4j.ServerProtocolFactory;
+
+import java.io.IOException;
+import java.rmi.AlreadyBoundException;
+
+/**
+ * @author Eike Stepper
+ */
+public class TestSignalProtocol extends SignalProtocol<Object>
+{
+ public static final String PROTOCOL_NAME = "signal.protocol"; //$NON-NLS-1$
+
+ public static final short SIGNAL_INT = 1;
+
+ public static final short SIGNAL_INT_FAIL = 2;
+
+ public static final short SIGNAL_ARRAY = 3;
+
+ public static final short SIGNAL_STRING = 4;
+
+ public static final short SIGNAL_ASYNC = 5;
+
+ public static final short SIGNAL_EXCEPTION = 6;
+
+ public static final String SIMULATED_EXCEPTION = "Simulated exception"; //$NON-NLS-1$
+
+ public TestSignalProtocol(IConnector connector)
+ {
+ this();
+ open(connector);
+ }
+
+ public TestSignalProtocol()
+ {
+ super(PROTOCOL_NAME);
+ }
+
+ @Override
+ protected SignalReactor createSignalReactor(short signalID)
+ {
+ switch (signalID)
+ {
+ case SIGNAL_INT:
+ return new IntIndication(this);
+
+ case SIGNAL_INT_FAIL:
+ return new IntFailIndication(this);
+
+ case SIGNAL_ARRAY:
+ return new ArrayIndication(this);
+
+ case SIGNAL_STRING:
+ return new StringIndication(this);
+
+ case SIGNAL_ASYNC:
+ return new AsyncIndication(this);
+
+ case SIGNAL_EXCEPTION:
+ return new ExceptionIndication(this);
+
+ default:
+ return super.createSignalReactor(signalID);
+ }
+ }
+
+ public void throwException(boolean ioProblem) throws Exception
+ {
+ if (ioProblem)
+ {
+ throw new IOException(SIMULATED_EXCEPTION);
+ }
+
+ try
+ {
+ throwNestedException();
+ }
+ catch (Exception ex)
+ {
+ throw new ClassNotFoundException(SIMULATED_EXCEPTION, ex);
+ }
+ }
+
+ public void throwNestedException() throws Exception
+ {
+ throw new AlreadyBoundException(SIMULATED_EXCEPTION);
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static class Factory extends ServerProtocolFactory
+ {
+ public Factory()
+ {
+ super(PROTOCOL_NAME);
+ }
+
+ public TestSignalProtocol create(String description) throws ProductCreationException
+ {
+ return new TestSignalProtocol();
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/AbstractOMTest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/AbstractOMTest.java
index 66c7ba43b8..295793e7d0 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/AbstractOMTest.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/AbstractOMTest.java
@@ -1,772 +1,772 @@
-/*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- */
-package org.eclipse.net4j.util.tests;
-
-import org.eclipse.net4j.tests.bundle.OM;
-import org.eclipse.net4j.util.concurrent.ConcurrencyUtil;
-import org.eclipse.net4j.util.event.EventUtil;
-import org.eclipse.net4j.util.event.IListener;
-import org.eclipse.net4j.util.io.IORuntimeException;
-import org.eclipse.net4j.util.io.IOUtil;
-import org.eclipse.net4j.util.io.TMPUtil;
-import org.eclipse.net4j.util.lifecycle.ILifecycle;
-import org.eclipse.net4j.util.lifecycle.LifecycleEventAdapter;
-import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
-import org.eclipse.net4j.util.om.OMPlatform;
-import org.eclipse.net4j.util.om.log.FileLogHandler;
-import org.eclipse.net4j.util.om.log.OMLogger;
-import org.eclipse.net4j.util.om.log.OMLogger.Level;
-import org.eclipse.net4j.util.om.log.PrintLogHandler;
-import org.eclipse.net4j.util.om.trace.ContextTracer;
-import org.eclipse.net4j.util.om.trace.PrintTraceHandler;
-
-import java.io.File;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Date;
-import java.util.List;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
-import java.util.concurrent.locks.Condition;
-import java.util.concurrent.locks.Lock;
-
-import junit.framework.Assert;
-import junit.framework.AssertionFailedError;
-import junit.framework.TestCase;
-import junit.framework.TestResult;
-
-/**
- * @author Eike Stepper
- */
-public abstract class AbstractOMTest extends TestCase
-{
- public static final long DEFAULT_TIMEOUT = 15 * 1000;
-
- public static final long DEFAULT_TIMEOUT_EXPECTED = 3 * 1000;
-
- private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, AbstractOMTest.class);
-
- public static boolean EXTERNAL_LOG;
-
- public static boolean SUPPRESS_OUTPUT;
-
- private static boolean consoleEnabled;
-
- private static String testName;
-
- private transient List<File> filesToDelete = new ArrayList<File>();
-
- private transient String codeLink;
-
- static
- {
- try
- {
- if (EXTERNAL_LOG)
- {
- SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
- String prefix = AbstractOMTest.class.getName() + "-" + formatter.format(new Date()) + "-";
- File logFile = TMPUtil.createTempFile(prefix, ".log");
-
- OMPlatform.INSTANCE.addLogHandler(new FileLogHandler(logFile, OMLogger.Level.WARN)
- {
- @Override
- protected void writeLog(OMLogger logger, Level level, String msg, Throwable t) throws Throwable
- {
- super.writeLog(logger, level, "--> " + testName + "\n" + msg, t);
- }
- });
-
- IOUtil.ERR().println("Logging errors and warnings to " + logFile);
- IOUtil.ERR().println();
- }
- }
- catch (Throwable ex)
- {
- IOUtil.print(ex);
- }
- }
-
- protected AbstractOMTest()
- {
- }
-
- public String getCodeLink()
- {
- return codeLink;
- }
-
- public void determineCodeLink()
- {
- if (codeLink == null)
- {
- codeLink = determineCodeLink(getName());
- if (codeLink == null)
- {
- codeLink = determineCodeLink("doSetUp");
- if (codeLink == null)
- {
- codeLink = getClass().getName() + "." + getName() + "(" + getClass().getSimpleName() + ".java:1)";
- }
- }
- }
- }
-
- protected String determineCodeLink(String methodName)
- {
- String className = getClass().getName();
- StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
- for (StackTraceElement frame : stackTrace)
- {
- if (frame.getClassName().equals(className) && frame.getMethodName().equals(methodName))
- {
- return frame.toString();
- }
- }
-
- return null;
- }
-
- @Override
- public void setUp() throws Exception
- {
- testName = getClass().getName() + "." + getName() + "()";
- codeLink = null;
-
- PrintTraceHandler.CONSOLE.setShortContext(true);
- OMPlatform.INSTANCE.addTraceHandler(PrintTraceHandler.CONSOLE);
- OMPlatform.INSTANCE.addLogHandler(PrintLogHandler.CONSOLE);
- enableConsole();
-
- if (!SUPPRESS_OUTPUT)
- {
- IOUtil.OUT().println("*******************************************************"); //$NON-NLS-1$
- Thread.yield();
- Thread.sleep(2L);
- IOUtil.ERR().println(this);
- Thread.yield();
- Thread.sleep(2L);
- IOUtil.OUT().println("*******************************************************"); //$NON-NLS-1$
- }
-
- super.setUp();
- doSetUp();
-
- if (!SUPPRESS_OUTPUT)
- {
- IOUtil.OUT().println();
- IOUtil.OUT().println("------------------------ START ------------------------"); //$NON-NLS-1$
- }
- }
-
- @Override
- public void tearDown() throws Exception
- {
- enableConsole();
- if (!SUPPRESS_OUTPUT)
- {
- IOUtil.OUT().println("------------------------- END -------------------------"); //$NON-NLS-1$
- IOUtil.OUT().println();
- }
-
- try
- {
- doTearDown();
- }
- catch (Exception ex)
- {
- IOUtil.print(ex);
- }
-
- try
- {
- super.tearDown();
- }
- catch (Exception ex)
- {
- IOUtil.print(ex);
- }
-
- if (!SUPPRESS_OUTPUT)
- {
- IOUtil.OUT().println();
- IOUtil.OUT().println();
- }
- }
-
- @Override
- public void runBare() throws Throwable
- {
- try
- {
- // Don't call super.runBare() because it does not clean up after exceptions from setUp()
- Throwable exception = null;
-
- try
- {
- setUp();
- runTest();
- }
- catch (Throwable running)
- {
- exception = running;
- }
- finally
- {
- try
- {
- tearDown();
- }
- catch (Throwable tearingDown)
- {
- if (exception == null)
- {
- exception = tearingDown;
- }
- }
- }
-
- if (exception != null)
- {
- throw exception;
- }
- }
- catch (SkipTestException ex)
- {
- OM.LOG.info("Skipped " + this); //$NON-NLS-1$
- }
- catch (Throwable t)
- {
- if (!SUPPRESS_OUTPUT)
- {
- t.printStackTrace(IOUtil.OUT());
- }
-
- throw t;
- }
- }
-
- @Override
- public void run(TestResult result)
- {
- try
- {
- super.run(result);
- }
- catch (SkipTestException ex)
- {
- OM.LOG.info("Skipped " + this); //$NON-NLS-1$
- }
- catch (RuntimeException ex)
- {
- if (!SUPPRESS_OUTPUT)
- {
- ex.printStackTrace(IOUtil.OUT());
- }
-
- throw ex;
- }
- catch (Error err)
- {
- if (!SUPPRESS_OUTPUT)
- {
- err.printStackTrace(IOUtil.OUT());
- }
-
- throw err;
- }
- }
-
- protected void enableConsole()
- {
- if (!SUPPRESS_OUTPUT)
- {
- OMPlatform.INSTANCE.setDebugging(true);
- consoleEnabled = true;
- }
- }
-
- protected void disableConsole()
- {
- if (!SUPPRESS_OUTPUT)
- {
- consoleEnabled = false;
- OMPlatform.INSTANCE.setDebugging(false);
- // OMPlatform.INSTANCE.removeTraceHandler(PrintTraceHandler.CONSOLE);
- // OMPlatform.INSTANCE.removeLogHandler(PrintLogHandler.CONSOLE);
- }
- }
-
- protected void doSetUp() throws Exception
- {
- }
-
- protected void doTearDown() throws Exception
- {
- deleteFiles();
- }
-
- public void deleteFiles()
- {
- for (File file : filesToDelete)
- {
- IOUtil.delete(file);
- }
-
- filesToDelete.clear();
- }
-
- public void addFileToDelete(File file)
- {
- filesToDelete.add(file);
- }
-
- public File createTempFolder() throws IORuntimeException
- {
- File folder = TMPUtil.createTempFolder();
- addFileToDelete(folder);
- return folder;
- }
-
- public File createTempFolder(String prefix) throws IORuntimeException
- {
- File folder = TMPUtil.createTempFolder(prefix);
- addFileToDelete(folder);
- return folder;
- }
-
- public File createTempFolder(String prefix, String suffix) throws IORuntimeException
- {
- File folder = TMPUtil.createTempFolder(prefix, suffix);
- addFileToDelete(folder);
- return folder;
- }
-
- public File createTempFolder(String prefix, String suffix, File directory) throws IORuntimeException
- {
- File folder = TMPUtil.createTempFile(prefix, suffix, directory);
- addFileToDelete(folder);
- return folder;
- }
-
- public File createTempFile() throws IORuntimeException
- {
- File file = TMPUtil.createTempFile();
- addFileToDelete(file);
- return file;
- }
-
- public File createTempFile(String prefix) throws IORuntimeException
- {
- File file = TMPUtil.createTempFile(prefix);
- addFileToDelete(file);
- return file;
- }
-
- public File createTempFile(String prefix, String suffix) throws IORuntimeException
- {
- File file = TMPUtil.createTempFile(prefix, suffix);
- addFileToDelete(file);
- return file;
- }
-
- public File createTempFile(String prefix, String suffix, File directory) throws IORuntimeException
- {
- File file = TMPUtil.createTempFile(prefix, suffix, directory);
- addFileToDelete(file);
- return file;
- }
-
- /**
- * @deprecated Use assertEquals(message, true, ...)
- */
- @Deprecated
- public static void assertTrue(String message, boolean condition)
- {
- throw new UnsupportedOperationException("Use assertEquals(message, true, ...)");
- }
-
- /**
- * @deprecated Use assertEquals(true, ...)
- */
- @Deprecated
- public static void assertTrue(boolean condition)
- {
- throw new UnsupportedOperationException("Use assertEquals(true, ...)");
- }
-
- /**
- * @deprecated Use assertEquals(message, false, ...)
- */
- @Deprecated
- public static void assertFalse(String message, boolean condition)
- {
- throw new UnsupportedOperationException("Use assertEquals(message, false, ...)");
- }
-
- /**
- * @deprecated Use assertEquals(false, ...)
- */
- @Deprecated
- public static void assertFalse(boolean condition)
- {
- throw new UnsupportedOperationException("Use assertEquals(false, ...)");
- }
-
- public static void assertEquals(Object[] expected, Object[] actual)
- {
- if (!Arrays.deepEquals(expected, actual))
- {
- throw new AssertionFailedError("expected:" + Arrays.deepToString(expected) + " but was:"
- + Arrays.deepToString(actual));
- }
- }
-
- public static void assertEquals(Object expected, Object actual)
- {
- // IMPORTANT: Give possible CDOLegacyWrapper a chance for actual, too
- if (actual != null && actual.equals(expected))
- {
- return;
- }
-
- Assert.assertEquals(expected, actual);
- }
-
- public static void assertEquals(String message, Object expected, Object actual)
- {
- if (expected == null && actual == null)
- {
- return;
- }
-
- if (expected != null && expected.equals(actual))
- {
- return;
- }
-
- // IMPORTANT: Give possible CDOLegacyWrapper a chance for actual, too
- if (actual != null && actual.equals(expected))
- {
- return;
- }
-
- failNotEquals(message, expected, actual);
- }
-
- public static void sleep(long millis)
- {
- msg("Sleeping " + millis);
- ConcurrencyUtil.sleep(millis);
- }
-
- public static void assertInstanceOf(Class<?> expected, Object object)
- {
- assertEquals("Not an instance of " + expected + ": " + object.getClass().getName(), true,
- expected.isInstance(object));
- }
-
- public static void assertActive(Object object) throws InterruptedException
- {
- final LatchTimeOuter timeOuter = new LatchTimeOuter();
- IListener listener = new LifecycleEventAdapter()
- {
- @Override
- protected void onActivated(ILifecycle lifecycle)
- {
- timeOuter.countDown();
- }
- };
-
- EventUtil.addListener(object, listener);
-
- try
- {
- if (LifecycleUtil.isActive(object))
- {
- timeOuter.countDown();
- }
-
- timeOuter.assertNoTimeOut();
- }
- finally
- {
- EventUtil.removeListener(object, listener);
- }
- }
-
- public static void assertInactive(Object object) throws InterruptedException
- {
- final LatchTimeOuter timeOuter = new LatchTimeOuter();
- IListener listener = new LifecycleEventAdapter()
- {
- @Override
- protected void onDeactivated(ILifecycle lifecycle)
- {
- timeOuter.countDown();
- }
- };
-
- EventUtil.addListener(object, listener);
-
- try
- {
- if (!LifecycleUtil.isActive(object))
- {
- timeOuter.countDown();
- }
-
- timeOuter.assertNoTimeOut();
- }
- finally
- {
- EventUtil.removeListener(object, listener);
- }
- }
-
- public static void assertSimilar(double expected, double actual, int precision)
- {
- final double factor = 10 * precision;
- if (Math.round(expected * factor) != Math.round(actual * factor))
- {
- assertEquals(expected, actual);
- }
- }
-
- public static void assertSimilar(float expected, float actual, int precision)
- {
- final float factor = 10 * precision;
- if (Math.round(expected * factor) != Math.round(actual * factor))
- {
- assertEquals(expected, actual);
- }
- }
-
- protected static void msg(Object m)
- {
- if (!SUPPRESS_OUTPUT)
- {
- if (consoleEnabled && TRACER.isEnabled())
- {
- TRACER.trace("--> " + m); //$NON-NLS-1$
- }
- }
- }
-
- protected static void skipTest(boolean skip)
- {
- if (skip)
- {
- throw new SkipTestException();
- }
- }
-
- protected static void skipTest()
- {
- skipTest(true);
- }
-
- /**
- * @author Eike Stepper
- */
- private static final class SkipTestException extends RuntimeException
- {
- private static final long serialVersionUID = 1L;
- }
-
- /**
- * @author Eike Stepper
- */
- public static class AsyncResult<T>
- {
- private volatile T value;
-
- private CountDownLatch latch = new CountDownLatch(1);
-
- public AsyncResult()
- {
- }
-
- public void setValue(T value)
- {
- this.value = value;
- latch.countDown();
- }
-
- public T getValue(long timeout) throws Exception
- {
- if (!latch.await(timeout, TimeUnit.MILLISECONDS))
- {
- throw new TimeoutException("Result value not available after " + timeout + " milli seconds");
- }
-
- return value;
- }
-
- public T getValue() throws Exception
- {
- return getValue(DEFAULT_TIMEOUT);
- }
- }
-
- /**
- * @author Eike Stepper
- */
- public static interface ITimeOuter
- {
- public boolean timedOut(long timeoutMillis) throws InterruptedException;
- }
-
- /**
- * @author Eike Stepper
- */
- public static abstract class TimeOuter implements ITimeOuter
- {
- public boolean timedOut() throws InterruptedException
- {
- return timedOut(DEFAULT_TIMEOUT);
- }
-
- public void assertTimeOut(long timeoutMillis) throws InterruptedException
- {
- assertEquals("Timeout expected", true, timedOut(timeoutMillis));
- }
-
- public void assertTimeOut() throws InterruptedException
- {
- assertTimeOut(DEFAULT_TIMEOUT_EXPECTED);
- }
-
- public void assertNoTimeOut(long timeoutMillis) throws InterruptedException
- {
- assertEquals("Timeout after " + timeoutMillis + " millis", false, timedOut(timeoutMillis));
- }
-
- public void assertNoTimeOut() throws InterruptedException
- {
- assertNoTimeOut(DEFAULT_TIMEOUT);
- }
- }
-
- /**
- * @author Eike Stepper
- */
- public static abstract class PollingTimeOuter extends TimeOuter
- {
- public static final long DEFAULT_SLEEP_MILLIS = 1;
-
- private long sleepMillis = DEFAULT_SLEEP_MILLIS;
-
- public PollingTimeOuter(long sleepMillis)
- {
- this.sleepMillis = sleepMillis;
- }
-
- public PollingTimeOuter()
- {
- }
-
- public boolean timedOut(long timeoutMillis) throws InterruptedException
- {
- int retries = (int)Math.round(timeoutMillis / sleepMillis + .5d);
- for (int i = 0; i < retries; i++)
- {
- if (successful())
- {
- return false;
- }
-
- sleep(sleepMillis);
- }
-
- return true;
- }
-
- protected abstract boolean successful();
- }
-
- /**
- * @author Eike Stepper
- */
- public static class LockTimeOuter extends TimeOuter
- {
- private Lock lock;
-
- public LockTimeOuter(Lock lock)
- {
- this.lock = lock;
- }
-
- public Lock getLock()
- {
- return lock;
- }
-
- public boolean timedOut(long timeoutMillis) throws InterruptedException
- {
- Condition condition = lock.newCondition();
- return !condition.await(timeoutMillis, TimeUnit.MILLISECONDS);
- }
- }
-
- /**
- * @author Eike Stepper
- */
- public static class LatchTimeOuter extends TimeOuter
- {
- private CountDownLatch latch;
-
- public LatchTimeOuter(CountDownLatch latch)
- {
- this.latch = latch;
- }
-
- public LatchTimeOuter(int count)
- {
- this(new CountDownLatch(count));
- }
-
- public LatchTimeOuter()
- {
- this(1);
- }
-
- public CountDownLatch getLatch()
- {
- return latch;
- }
-
- public long getCount()
- {
- return latch.getCount();
- }
-
- public void countDown()
- {
- latch.countDown();
- }
-
- public void countDown(int n)
- {
- for (int i = 0; i < n; i++)
- {
- countDown();
- }
- }
-
- public boolean timedOut(long timeoutMillis) throws InterruptedException
- {
- return !latch.await(timeoutMillis, TimeUnit.MILLISECONDS);
- }
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.util.tests;
+
+import org.eclipse.net4j.tests.bundle.OM;
+import org.eclipse.net4j.util.concurrent.ConcurrencyUtil;
+import org.eclipse.net4j.util.event.EventUtil;
+import org.eclipse.net4j.util.event.IListener;
+import org.eclipse.net4j.util.io.IORuntimeException;
+import org.eclipse.net4j.util.io.IOUtil;
+import org.eclipse.net4j.util.io.TMPUtil;
+import org.eclipse.net4j.util.lifecycle.ILifecycle;
+import org.eclipse.net4j.util.lifecycle.LifecycleEventAdapter;
+import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
+import org.eclipse.net4j.util.om.OMPlatform;
+import org.eclipse.net4j.util.om.log.FileLogHandler;
+import org.eclipse.net4j.util.om.log.OMLogger;
+import org.eclipse.net4j.util.om.log.OMLogger.Level;
+import org.eclipse.net4j.util.om.log.PrintLogHandler;
+import org.eclipse.net4j.util.om.trace.ContextTracer;
+import org.eclipse.net4j.util.om.trace.PrintTraceHandler;
+
+import java.io.File;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.List;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+import java.util.concurrent.locks.Condition;
+import java.util.concurrent.locks.Lock;
+
+import junit.framework.Assert;
+import junit.framework.AssertionFailedError;
+import junit.framework.TestCase;
+import junit.framework.TestResult;
+
+/**
+ * @author Eike Stepper
+ */
+public abstract class AbstractOMTest extends TestCase
+{
+ public static final long DEFAULT_TIMEOUT = 15 * 1000;
+
+ public static final long DEFAULT_TIMEOUT_EXPECTED = 3 * 1000;
+
+ private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, AbstractOMTest.class);
+
+ public static boolean EXTERNAL_LOG;
+
+ public static boolean SUPPRESS_OUTPUT;
+
+ private static boolean consoleEnabled;
+
+ private static String testName;
+
+ private transient List<File> filesToDelete = new ArrayList<File>();
+
+ private transient String codeLink;
+
+ static
+ {
+ try
+ {
+ if (EXTERNAL_LOG)
+ {
+ SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmss");
+ String prefix = AbstractOMTest.class.getName() + "-" + formatter.format(new Date()) + "-";
+ File logFile = TMPUtil.createTempFile(prefix, ".log");
+
+ OMPlatform.INSTANCE.addLogHandler(new FileLogHandler(logFile, OMLogger.Level.WARN)
+ {
+ @Override
+ protected void writeLog(OMLogger logger, Level level, String msg, Throwable t) throws Throwable
+ {
+ super.writeLog(logger, level, "--> " + testName + "\n" + msg, t);
+ }
+ });
+
+ IOUtil.ERR().println("Logging errors and warnings to " + logFile);
+ IOUtil.ERR().println();
+ }
+ }
+ catch (Throwable ex)
+ {
+ IOUtil.print(ex);
+ }
+ }
+
+ protected AbstractOMTest()
+ {
+ }
+
+ public String getCodeLink()
+ {
+ return codeLink;
+ }
+
+ public void determineCodeLink()
+ {
+ if (codeLink == null)
+ {
+ codeLink = determineCodeLink(getName());
+ if (codeLink == null)
+ {
+ codeLink = determineCodeLink("doSetUp");
+ if (codeLink == null)
+ {
+ codeLink = getClass().getName() + "." + getName() + "(" + getClass().getSimpleName() + ".java:1)";
+ }
+ }
+ }
+ }
+
+ protected String determineCodeLink(String methodName)
+ {
+ String className = getClass().getName();
+ StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
+ for (StackTraceElement frame : stackTrace)
+ {
+ if (frame.getClassName().equals(className) && frame.getMethodName().equals(methodName))
+ {
+ return frame.toString();
+ }
+ }
+
+ return null;
+ }
+
+ @Override
+ public void setUp() throws Exception
+ {
+ testName = getClass().getName() + "." + getName() + "()";
+ codeLink = null;
+
+ PrintTraceHandler.CONSOLE.setShortContext(true);
+ OMPlatform.INSTANCE.addTraceHandler(PrintTraceHandler.CONSOLE);
+ OMPlatform.INSTANCE.addLogHandler(PrintLogHandler.CONSOLE);
+ enableConsole();
+
+ if (!SUPPRESS_OUTPUT)
+ {
+ IOUtil.OUT().println("*******************************************************"); //$NON-NLS-1$
+ Thread.yield();
+ Thread.sleep(2L);
+ IOUtil.ERR().println(this);
+ Thread.yield();
+ Thread.sleep(2L);
+ IOUtil.OUT().println("*******************************************************"); //$NON-NLS-1$
+ }
+
+ super.setUp();
+ doSetUp();
+
+ if (!SUPPRESS_OUTPUT)
+ {
+ IOUtil.OUT().println();
+ IOUtil.OUT().println("------------------------ START ------------------------"); //$NON-NLS-1$
+ }
+ }
+
+ @Override
+ public void tearDown() throws Exception
+ {
+ enableConsole();
+ if (!SUPPRESS_OUTPUT)
+ {
+ IOUtil.OUT().println("------------------------- END -------------------------"); //$NON-NLS-1$
+ IOUtil.OUT().println();
+ }
+
+ try
+ {
+ doTearDown();
+ }
+ catch (Exception ex)
+ {
+ IOUtil.print(ex);
+ }
+
+ try
+ {
+ super.tearDown();
+ }
+ catch (Exception ex)
+ {
+ IOUtil.print(ex);
+ }
+
+ if (!SUPPRESS_OUTPUT)
+ {
+ IOUtil.OUT().println();
+ IOUtil.OUT().println();
+ }
+ }
+
+ @Override
+ public void runBare() throws Throwable
+ {
+ try
+ {
+ // Don't call super.runBare() because it does not clean up after exceptions from setUp()
+ Throwable exception = null;
+
+ try
+ {
+ setUp();
+ runTest();
+ }
+ catch (Throwable running)
+ {
+ exception = running;
+ }
+ finally
+ {
+ try
+ {
+ tearDown();
+ }
+ catch (Throwable tearingDown)
+ {
+ if (exception == null)
+ {
+ exception = tearingDown;
+ }
+ }
+ }
+
+ if (exception != null)
+ {
+ throw exception;
+ }
+ }
+ catch (SkipTestException ex)
+ {
+ OM.LOG.info("Skipped " + this); //$NON-NLS-1$
+ }
+ catch (Throwable t)
+ {
+ if (!SUPPRESS_OUTPUT)
+ {
+ t.printStackTrace(IOUtil.OUT());
+ }
+
+ throw t;
+ }
+ }
+
+ @Override
+ public void run(TestResult result)
+ {
+ try
+ {
+ super.run(result);
+ }
+ catch (SkipTestException ex)
+ {
+ OM.LOG.info("Skipped " + this); //$NON-NLS-1$
+ }
+ catch (RuntimeException ex)
+ {
+ if (!SUPPRESS_OUTPUT)
+ {
+ ex.printStackTrace(IOUtil.OUT());
+ }
+
+ throw ex;
+ }
+ catch (Error err)
+ {
+ if (!SUPPRESS_OUTPUT)
+ {
+ err.printStackTrace(IOUtil.OUT());
+ }
+
+ throw err;
+ }
+ }
+
+ protected void enableConsole()
+ {
+ if (!SUPPRESS_OUTPUT)
+ {
+ OMPlatform.INSTANCE.setDebugging(true);
+ consoleEnabled = true;
+ }
+ }
+
+ protected void disableConsole()
+ {
+ if (!SUPPRESS_OUTPUT)
+ {
+ consoleEnabled = false;
+ OMPlatform.INSTANCE.setDebugging(false);
+ // OMPlatform.INSTANCE.removeTraceHandler(PrintTraceHandler.CONSOLE);
+ // OMPlatform.INSTANCE.removeLogHandler(PrintLogHandler.CONSOLE);
+ }
+ }
+
+ protected void doSetUp() throws Exception
+ {
+ }
+
+ protected void doTearDown() throws Exception
+ {
+ deleteFiles();
+ }
+
+ public void deleteFiles()
+ {
+ for (File file : filesToDelete)
+ {
+ IOUtil.delete(file);
+ }
+
+ filesToDelete.clear();
+ }
+
+ public void addFileToDelete(File file)
+ {
+ filesToDelete.add(file);
+ }
+
+ public File createTempFolder() throws IORuntimeException
+ {
+ File folder = TMPUtil.createTempFolder();
+ addFileToDelete(folder);
+ return folder;
+ }
+
+ public File createTempFolder(String prefix) throws IORuntimeException
+ {
+ File folder = TMPUtil.createTempFolder(prefix);
+ addFileToDelete(folder);
+ return folder;
+ }
+
+ public File createTempFolder(String prefix, String suffix) throws IORuntimeException
+ {
+ File folder = TMPUtil.createTempFolder(prefix, suffix);
+ addFileToDelete(folder);
+ return folder;
+ }
+
+ public File createTempFolder(String prefix, String suffix, File directory) throws IORuntimeException
+ {
+ File folder = TMPUtil.createTempFile(prefix, suffix, directory);
+ addFileToDelete(folder);
+ return folder;
+ }
+
+ public File createTempFile() throws IORuntimeException
+ {
+ File file = TMPUtil.createTempFile();
+ addFileToDelete(file);
+ return file;
+ }
+
+ public File createTempFile(String prefix) throws IORuntimeException
+ {
+ File file = TMPUtil.createTempFile(prefix);
+ addFileToDelete(file);
+ return file;
+ }
+
+ public File createTempFile(String prefix, String suffix) throws IORuntimeException
+ {
+ File file = TMPUtil.createTempFile(prefix, suffix);
+ addFileToDelete(file);
+ return file;
+ }
+
+ public File createTempFile(String prefix, String suffix, File directory) throws IORuntimeException
+ {
+ File file = TMPUtil.createTempFile(prefix, suffix, directory);
+ addFileToDelete(file);
+ return file;
+ }
+
+ /**
+ * @deprecated Use assertEquals(message, true, ...)
+ */
+ @Deprecated
+ public static void assertTrue(String message, boolean condition)
+ {
+ throw new UnsupportedOperationException("Use assertEquals(message, true, ...)");
+ }
+
+ /**
+ * @deprecated Use assertEquals(true, ...)
+ */
+ @Deprecated
+ public static void assertTrue(boolean condition)
+ {
+ throw new UnsupportedOperationException("Use assertEquals(true, ...)");
+ }
+
+ /**
+ * @deprecated Use assertEquals(message, false, ...)
+ */
+ @Deprecated
+ public static void assertFalse(String message, boolean condition)
+ {
+ throw new UnsupportedOperationException("Use assertEquals(message, false, ...)");
+ }
+
+ /**
+ * @deprecated Use assertEquals(false, ...)
+ */
+ @Deprecated
+ public static void assertFalse(boolean condition)
+ {
+ throw new UnsupportedOperationException("Use assertEquals(false, ...)");
+ }
+
+ public static void assertEquals(Object[] expected, Object[] actual)
+ {
+ if (!Arrays.deepEquals(expected, actual))
+ {
+ throw new AssertionFailedError("expected:" + Arrays.deepToString(expected) + " but was:"
+ + Arrays.deepToString(actual));
+ }
+ }
+
+ public static void assertEquals(Object expected, Object actual)
+ {
+ // IMPORTANT: Give possible CDOLegacyWrapper a chance for actual, too
+ if (actual != null && actual.equals(expected))
+ {
+ return;
+ }
+
+ Assert.assertEquals(expected, actual);
+ }
+
+ public static void assertEquals(String message, Object expected, Object actual)
+ {
+ if (expected == null && actual == null)
+ {
+ return;
+ }
+
+ if (expected != null && expected.equals(actual))
+ {
+ return;
+ }
+
+ // IMPORTANT: Give possible CDOLegacyWrapper a chance for actual, too
+ if (actual != null && actual.equals(expected))
+ {
+ return;
+ }
+
+ failNotEquals(message, expected, actual);
+ }
+
+ public static void sleep(long millis)
+ {
+ msg("Sleeping " + millis);
+ ConcurrencyUtil.sleep(millis);
+ }
+
+ public static void assertInstanceOf(Class<?> expected, Object object)
+ {
+ assertEquals("Not an instance of " + expected + ": " + object.getClass().getName(), true,
+ expected.isInstance(object));
+ }
+
+ public static void assertActive(Object object) throws InterruptedException
+ {
+ final LatchTimeOuter timeOuter = new LatchTimeOuter();
+ IListener listener = new LifecycleEventAdapter()
+ {
+ @Override
+ protected void onActivated(ILifecycle lifecycle)
+ {
+ timeOuter.countDown();
+ }
+ };
+
+ EventUtil.addListener(object, listener);
+
+ try
+ {
+ if (LifecycleUtil.isActive(object))
+ {
+ timeOuter.countDown();
+ }
+
+ timeOuter.assertNoTimeOut();
+ }
+ finally
+ {
+ EventUtil.removeListener(object, listener);
+ }
+ }
+
+ public static void assertInactive(Object object) throws InterruptedException
+ {
+ final LatchTimeOuter timeOuter = new LatchTimeOuter();
+ IListener listener = new LifecycleEventAdapter()
+ {
+ @Override
+ protected void onDeactivated(ILifecycle lifecycle)
+ {
+ timeOuter.countDown();
+ }
+ };
+
+ EventUtil.addListener(object, listener);
+
+ try
+ {
+ if (!LifecycleUtil.isActive(object))
+ {
+ timeOuter.countDown();
+ }
+
+ timeOuter.assertNoTimeOut();
+ }
+ finally
+ {
+ EventUtil.removeListener(object, listener);
+ }
+ }
+
+ public static void assertSimilar(double expected, double actual, int precision)
+ {
+ final double factor = 10 * precision;
+ if (Math.round(expected * factor) != Math.round(actual * factor))
+ {
+ assertEquals(expected, actual);
+ }
+ }
+
+ public static void assertSimilar(float expected, float actual, int precision)
+ {
+ final float factor = 10 * precision;
+ if (Math.round(expected * factor) != Math.round(actual * factor))
+ {
+ assertEquals(expected, actual);
+ }
+ }
+
+ protected static void msg(Object m)
+ {
+ if (!SUPPRESS_OUTPUT)
+ {
+ if (consoleEnabled && TRACER.isEnabled())
+ {
+ TRACER.trace("--> " + m); //$NON-NLS-1$
+ }
+ }
+ }
+
+ protected static void skipTest(boolean skip)
+ {
+ if (skip)
+ {
+ throw new SkipTestException();
+ }
+ }
+
+ protected static void skipTest()
+ {
+ skipTest(true);
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ private static final class SkipTestException extends RuntimeException
+ {
+ private static final long serialVersionUID = 1L;
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static class AsyncResult<T>
+ {
+ private volatile T value;
+
+ private CountDownLatch latch = new CountDownLatch(1);
+
+ public AsyncResult()
+ {
+ }
+
+ public void setValue(T value)
+ {
+ this.value = value;
+ latch.countDown();
+ }
+
+ public T getValue(long timeout) throws Exception
+ {
+ if (!latch.await(timeout, TimeUnit.MILLISECONDS))
+ {
+ throw new TimeoutException("Result value not available after " + timeout + " milli seconds");
+ }
+
+ return value;
+ }
+
+ public T getValue() throws Exception
+ {
+ return getValue(DEFAULT_TIMEOUT);
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static interface ITimeOuter
+ {
+ public boolean timedOut(long timeoutMillis) throws InterruptedException;
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static abstract class TimeOuter implements ITimeOuter
+ {
+ public boolean timedOut() throws InterruptedException
+ {
+ return timedOut(DEFAULT_TIMEOUT);
+ }
+
+ public void assertTimeOut(long timeoutMillis) throws InterruptedException
+ {
+ assertEquals("Timeout expected", true, timedOut(timeoutMillis));
+ }
+
+ public void assertTimeOut() throws InterruptedException
+ {
+ assertTimeOut(DEFAULT_TIMEOUT_EXPECTED);
+ }
+
+ public void assertNoTimeOut(long timeoutMillis) throws InterruptedException
+ {
+ assertEquals("Timeout after " + timeoutMillis + " millis", false, timedOut(timeoutMillis));
+ }
+
+ public void assertNoTimeOut() throws InterruptedException
+ {
+ assertNoTimeOut(DEFAULT_TIMEOUT);
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static abstract class PollingTimeOuter extends TimeOuter
+ {
+ public static final long DEFAULT_SLEEP_MILLIS = 1;
+
+ private long sleepMillis = DEFAULT_SLEEP_MILLIS;
+
+ public PollingTimeOuter(long sleepMillis)
+ {
+ this.sleepMillis = sleepMillis;
+ }
+
+ public PollingTimeOuter()
+ {
+ }
+
+ public boolean timedOut(long timeoutMillis) throws InterruptedException
+ {
+ int retries = (int)Math.round(timeoutMillis / sleepMillis + .5d);
+ for (int i = 0; i < retries; i++)
+ {
+ if (successful())
+ {
+ return false;
+ }
+
+ sleep(sleepMillis);
+ }
+
+ return true;
+ }
+
+ protected abstract boolean successful();
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static class LockTimeOuter extends TimeOuter
+ {
+ private Lock lock;
+
+ public LockTimeOuter(Lock lock)
+ {
+ this.lock = lock;
+ }
+
+ public Lock getLock()
+ {
+ return lock;
+ }
+
+ public boolean timedOut(long timeoutMillis) throws InterruptedException
+ {
+ Condition condition = lock.newCondition();
+ return !condition.await(timeoutMillis, TimeUnit.MILLISECONDS);
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static class LatchTimeOuter extends TimeOuter
+ {
+ private CountDownLatch latch;
+
+ public LatchTimeOuter(CountDownLatch latch)
+ {
+ this.latch = latch;
+ }
+
+ public LatchTimeOuter(int count)
+ {
+ this(new CountDownLatch(count));
+ }
+
+ public LatchTimeOuter()
+ {
+ this(1);
+ }
+
+ public CountDownLatch getLatch()
+ {
+ return latch;
+ }
+
+ public long getCount()
+ {
+ return latch.getCount();
+ }
+
+ public void countDown()
+ {
+ latch.countDown();
+ }
+
+ public void countDown(int n)
+ {
+ for (int i = 0; i < n; i++)
+ {
+ countDown();
+ }
+ }
+
+ public boolean timedOut(long timeoutMillis) throws InterruptedException
+ {
+ return !latch.await(timeoutMillis, TimeUnit.MILLISECONDS);
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/ConcurrentRunner.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/ConcurrentRunner.java
index d08b2442a1..fcb7de36c5 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/ConcurrentRunner.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/ConcurrentRunner.java
@@ -1,140 +1,140 @@
-/*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Andre Dietisheim - initial API and implementation
- * Eike Stepper - maintenance
- */
-package org.eclipse.net4j.util.tests;
-
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
-
-/**
- * A class that implements a concurrent execution environment for runnables. It waits until all runnables submitted for
- * execution are terminated and returns the first throwable that occurs
- *
- * @author Andre Dietisheim
- */
-public class ConcurrentRunner
-{
- /**
- * Executes Runnables in concurrent manner. The first Throwable thrown by those runnables is thrown back to the
- * caller.
- *
- * @param runnables
- * the runnables to execute
- * @param maxThreads
- * the maximum number of threads to use
- * @param numOfExecution
- * the number of executions per runnable
- * @throws Throwable
- * the throwable
- */
- public static void run(Runnable[] runnables, int maxThreads, int numOfExecution) throws Throwable
- {
- ExecutorService threadPool = Executors.newFixedThreadPool(maxThreads);
- Future<Throwable>[] futures = execute(numOfExecution, threadPool, runnables);
- throwOnFailure(futures, threadPool);
- }
-
- /**
- * Executes the runnables. The runnables are wrapped in Callables when they're submitted to the thread pool.
- *
- * @param loops
- * the loops
- * @param threadPool
- * the thread pool
- * @param runnables
- * the runnables
- * @return the future<throwable>[] that allow to wait for the runnables result
- */
- @SuppressWarnings("unchecked")
- private static Future<Throwable>[] execute(int loops, ExecutorService threadPool, Runnable[] runnables)
- {
- Future<Throwable>[] futures = new Future[loops * runnables.length];
- for (int j = 0; j < loops; j++)
- {
- for (int i = 0; i < runnables.length; i++)
- {
- futures[j * runnables.length + i] = threadPool.submit(new ThrowableCatchingWrapper(runnables[i]));
- }
- }
-
- return futures;
- }
-
- /**
- * Throw a throwable if it occured while executing the runnables
- *
- * @param futures
- * the futures
- * @param threadPool
- * @throws InterruptedException
- * the interrupted exception
- * @throws ExecutionException
- * the execution exception
- * @throws Throwable
- * the throwable
- */
- private static void throwOnFailure(Future<Throwable>[] futures, ExecutorService threadPool)
- throws InterruptedException, ExecutionException, Throwable
- {
- for (Future<Throwable> future : futures)
- {
- Throwable e = future.get();
- if (e != null)
- {
- threadPool.shutdownNow();
- throw e;
- }
- }
- }
-
- /**
- * A Wrapper for runnables that catches a Throwable that occur when running the runnable
- */
- private static class ThrowableCatchingWrapper implements Callable<Throwable>
- {
- /** The runnable. */
- private Runnable runnable;
-
- /**
- * Instantiates a new concurrent test case.
- *
- * @param runnable
- * the runnable
- */
- private ThrowableCatchingWrapper(Runnable runnable)
- {
- this.runnable = runnable;
- }
-
- /**
- * Call.
- *
- * @return the throwable
- * @throws Exception
- * the exception
- */
- public Throwable call() throws Exception
- {
- try
- {
- runnable.run();
- return null;
- }
- catch (Throwable t)
- {
- return t;
- }
- }
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Andre Dietisheim - initial API and implementation
+ * Eike Stepper - maintenance
+ */
+package org.eclipse.net4j.util.tests;
+
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+
+/**
+ * A class that implements a concurrent execution environment for runnables. It waits until all runnables submitted for
+ * execution are terminated and returns the first throwable that occurs
+ *
+ * @author Andre Dietisheim
+ */
+public class ConcurrentRunner
+{
+ /**
+ * Executes Runnables in concurrent manner. The first Throwable thrown by those runnables is thrown back to the
+ * caller.
+ *
+ * @param runnables
+ * the runnables to execute
+ * @param maxThreads
+ * the maximum number of threads to use
+ * @param numOfExecution
+ * the number of executions per runnable
+ * @throws Throwable
+ * the throwable
+ */
+ public static void run(Runnable[] runnables, int maxThreads, int numOfExecution) throws Throwable
+ {
+ ExecutorService threadPool = Executors.newFixedThreadPool(maxThreads);
+ Future<Throwable>[] futures = execute(numOfExecution, threadPool, runnables);
+ throwOnFailure(futures, threadPool);
+ }
+
+ /**
+ * Executes the runnables. The runnables are wrapped in Callables when they're submitted to the thread pool.
+ *
+ * @param loops
+ * the loops
+ * @param threadPool
+ * the thread pool
+ * @param runnables
+ * the runnables
+ * @return the future<throwable>[] that allow to wait for the runnables result
+ */
+ @SuppressWarnings("unchecked")
+ private static Future<Throwable>[] execute(int loops, ExecutorService threadPool, Runnable[] runnables)
+ {
+ Future<Throwable>[] futures = new Future[loops * runnables.length];
+ for (int j = 0; j < loops; j++)
+ {
+ for (int i = 0; i < runnables.length; i++)
+ {
+ futures[j * runnables.length + i] = threadPool.submit(new ThrowableCatchingWrapper(runnables[i]));
+ }
+ }
+
+ return futures;
+ }
+
+ /**
+ * Throw a throwable if it occured while executing the runnables
+ *
+ * @param futures
+ * the futures
+ * @param threadPool
+ * @throws InterruptedException
+ * the interrupted exception
+ * @throws ExecutionException
+ * the execution exception
+ * @throws Throwable
+ * the throwable
+ */
+ private static void throwOnFailure(Future<Throwable>[] futures, ExecutorService threadPool)
+ throws InterruptedException, ExecutionException, Throwable
+ {
+ for (Future<Throwable> future : futures)
+ {
+ Throwable e = future.get();
+ if (e != null)
+ {
+ threadPool.shutdownNow();
+ throw e;
+ }
+ }
+ }
+
+ /**
+ * A Wrapper for runnables that catches a Throwable that occur when running the runnable
+ */
+ private static class ThrowableCatchingWrapper implements Callable<Throwable>
+ {
+ /** The runnable. */
+ private Runnable runnable;
+
+ /**
+ * Instantiates a new concurrent test case.
+ *
+ * @param runnable
+ * the runnable
+ */
+ private ThrowableCatchingWrapper(Runnable runnable)
+ {
+ this.runnable = runnable;
+ }
+
+ /**
+ * Call.
+ *
+ * @return the throwable
+ * @throws Exception
+ * the exception
+ */
+ public Throwable call() throws Exception
+ {
+ try
+ {
+ runnable.run();
+ return null;
+ }
+ catch (Throwable t)
+ {
+ return t;
+ }
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/ExpectedIOTest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/ExpectedIOTest.java
index a82ff20dbd..6ec72c2142 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/ExpectedIOTest.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/ExpectedIOTest.java
@@ -1,390 +1,390 @@
-/*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- */
-package org.eclipse.net4j.util.tests;
-
-import org.eclipse.net4j.util.concurrent.ConcurrencyUtil;
-import org.eclipse.net4j.util.io.ExpectedFileInputStream;
-import org.eclipse.net4j.util.io.ExpectedFileReader;
-import org.eclipse.net4j.util.io.IOUtil;
-
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.EOFException;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.FileWriter;
-import java.io.Reader;
-import java.io.Writer;
-
-/**
- * @author Eike Stepper
- */
-public class ExpectedIOTest extends AbstractOMTest
-{
- private Exception exception;
-
- @Override
- protected void doSetUp() throws Exception
- {
- super.doSetUp();
- exception = null;
- }
-
- public void testInputStream() throws Exception
- {
- final File file = createTempFile("ExpectedIOTest", ".tmp");
- final int LOOPS = 30;
-
- Thread producer = new Thread("PRODUCER")
- {
- @Override
- public void run()
- {
- DataOutputStream out = null;
-
- try
- {
- out = new DataOutputStream(new FileOutputStream(file));
- for (int i = 0; i < LOOPS; i++)
- {
- out.writeInt(i);
- IOUtil.ERR().println(i);
- ConcurrencyUtil.sleep(100);
- }
- }
- catch (Exception ex)
- {
- if (exception == null)
- {
- exception = ex;
- }
- }
- finally
- {
- IOUtil.close(out);
- }
- }
- };
-
- Thread consumer = new Thread("CONSUMER")
- {
- @Override
- public void run()
- {
- DataInputStream in = null;
-
- try
- {
- in = new DataInputStream(new ExpectedFileInputStream(file, LOOPS * 4));
-
- for (int i = 0; i < LOOPS; i++)
- {
- System.out.println(in.readInt());
- }
- }
- catch (Exception ex)
- {
- if (exception == null)
- {
- exception = ex;
- }
- }
- finally
- {
- IOUtil.close(in);
- }
- }
- };
-
- producer.start();
- ConcurrencyUtil.sleep(500);
- consumer.start();
-
- producer.join();
- consumer.join();
-
- if (exception != null)
- {
- throw exception;
- }
- }
-
- public void testInputStreamEOF() throws Exception
- {
- final File file = File.createTempFile("ExpectedIOTest", ".tmp");
- final int LOOPS = 30;
-
- Thread producer = new Thread("PRODUCER")
- {
- @Override
- public void run()
- {
- DataOutputStream out = null;
-
- try
- {
- out = new DataOutputStream(new FileOutputStream(file));
- for (int i = 0; i < LOOPS; i++)
- {
- out.writeInt(i);
- IOUtil.ERR().println(i);
- ConcurrencyUtil.sleep(100);
- }
- }
- catch (Exception ex)
- {
- if (exception == null)
- {
- exception = ex;
- }
- }
- finally
- {
- IOUtil.close(out);
- }
- }
- };
-
- Thread consumer = new Thread("CONSUMER")
- {
- @Override
- public void run()
- {
- DataInputStream in = null;
-
- try
- {
- in = new DataInputStream(new ExpectedFileInputStream(file, LOOPS * 4));
-
- for (int i = 0; i < LOOPS + 10; i++)
- {
- System.out.println(in.readInt());
- }
- }
- catch (Exception ex)
- {
- if (exception == null)
- {
- exception = ex;
- }
- }
- finally
- {
- IOUtil.close(in);
- }
- }
- };
-
- producer.start();
- ConcurrencyUtil.sleep(500);
- consumer.start();
-
- producer.join();
- consumer.join();
-
- if (!(exception instanceof EOFException))
- {
- throw exception;
- }
- }
-
- public void testReader() throws Exception
- {
- final File file = File.createTempFile("ExpectedIOTest", ".tmp");
- final int LOOPS = 30;
-
- Thread producer = new Thread("PRODUCER")
- {
- @Override
- public void run()
- {
- Writer out = null;
-
- try
- {
- out = new FileWriter(file);
- for (int i = 0; i < LOOPS; i++)
- {
- int c = 'a' + i;
- out.write(c);
- IOUtil.ERR().println(c);
-
- out.write(c + 1);
- IOUtil.ERR().println(c + 1);
- ConcurrencyUtil.sleep(100);
- }
- }
- catch (Exception ex)
- {
- if (exception == null)
- {
- exception = ex;
- }
- }
- finally
- {
- IOUtil.close(out);
- }
- }
- };
-
- Thread consumer = new Thread("CONSUMER")
- {
- @Override
- public void run()
- {
- Reader in = null;
-
- try
- {
- in = new ExpectedFileReader(file, LOOPS * 2);
-
- for (int i = 0; i < LOOPS; i++)
- {
- int c = in.read();
- if (c == -1)
- {
- throw new EOFException();
- }
-
- System.out.println(c);
- c = in.read();
- if (c == -1)
- {
- throw new EOFException();
- }
-
- System.out.println(c);
- }
- }
- catch (Exception ex)
- {
- if (exception == null)
- {
- exception = ex;
- }
- }
- finally
- {
- IOUtil.close(in);
- }
- }
- };
-
- producer.start();
- ConcurrencyUtil.sleep(500);
- consumer.start();
-
- producer.join();
- consumer.join();
-
- if (exception != null)
- {
- throw exception;
- }
- }
-
- public void testReaderEOF() throws Exception
- {
- final File file = File.createTempFile("ExpectedIOTest", ".tmp");
- final int LOOPS = 30;
-
- Thread producer = new Thread("PRODUCER")
- {
- @Override
- public void run()
- {
- Writer out = null;
-
- try
- {
- out = new FileWriter(file);
- for (int i = 0; i < LOOPS; i++)
- {
- int c = 'a' + i;
- out.write(c);
- IOUtil.ERR().println(c);
-
- out.write(c + 1);
- IOUtil.ERR().println(c + 1);
- ConcurrencyUtil.sleep(100);
- }
- }
- catch (Exception ex)
- {
- if (exception == null)
- {
- exception = ex;
- }
- }
- finally
- {
- IOUtil.close(out);
- }
- }
- };
-
- Thread consumer = new Thread("CONSUMER")
- {
- @Override
- public void run()
- {
- Reader in = null;
-
- try
- {
- in = new ExpectedFileReader(file, LOOPS * 2);
-
- for (int i = 0; i < LOOPS + 10; i++)
- {
- int c = in.read();
- if (c == -1)
- {
- throw new EOFException();
- }
-
- System.out.println(c);
- c = in.read();
- if (c == -1)
- {
- throw new EOFException();
- }
-
- System.out.println(c);
- }
- }
- catch (Exception ex)
- {
- if (exception == null)
- {
- exception = ex;
- }
- }
- finally
- {
- IOUtil.close(in);
- }
- }
- };
-
- producer.start();
- ConcurrencyUtil.sleep(500);
- consumer.start();
-
- producer.join();
- consumer.join();
-
- if (!(exception instanceof EOFException))
- {
- throw exception;
- }
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.util.tests;
+
+import org.eclipse.net4j.util.concurrent.ConcurrencyUtil;
+import org.eclipse.net4j.util.io.ExpectedFileInputStream;
+import org.eclipse.net4j.util.io.ExpectedFileReader;
+import org.eclipse.net4j.util.io.IOUtil;
+
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.EOFException;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.FileWriter;
+import java.io.Reader;
+import java.io.Writer;
+
+/**
+ * @author Eike Stepper
+ */
+public class ExpectedIOTest extends AbstractOMTest
+{
+ private Exception exception;
+
+ @Override
+ protected void doSetUp() throws Exception
+ {
+ super.doSetUp();
+ exception = null;
+ }
+
+ public void testInputStream() throws Exception
+ {
+ final File file = createTempFile("ExpectedIOTest", ".tmp");
+ final int LOOPS = 30;
+
+ Thread producer = new Thread("PRODUCER")
+ {
+ @Override
+ public void run()
+ {
+ DataOutputStream out = null;
+
+ try
+ {
+ out = new DataOutputStream(new FileOutputStream(file));
+ for (int i = 0; i < LOOPS; i++)
+ {
+ out.writeInt(i);
+ IOUtil.ERR().println(i);
+ ConcurrencyUtil.sleep(100);
+ }
+ }
+ catch (Exception ex)
+ {
+ if (exception == null)
+ {
+ exception = ex;
+ }
+ }
+ finally
+ {
+ IOUtil.close(out);
+ }
+ }
+ };
+
+ Thread consumer = new Thread("CONSUMER")
+ {
+ @Override
+ public void run()
+ {
+ DataInputStream in = null;
+
+ try
+ {
+ in = new DataInputStream(new ExpectedFileInputStream(file, LOOPS * 4));
+
+ for (int i = 0; i < LOOPS; i++)
+ {
+ System.out.println(in.readInt());
+ }
+ }
+ catch (Exception ex)
+ {
+ if (exception == null)
+ {
+ exception = ex;
+ }
+ }
+ finally
+ {
+ IOUtil.close(in);
+ }
+ }
+ };
+
+ producer.start();
+ ConcurrencyUtil.sleep(500);
+ consumer.start();
+
+ producer.join();
+ consumer.join();
+
+ if (exception != null)
+ {
+ throw exception;
+ }
+ }
+
+ public void testInputStreamEOF() throws Exception
+ {
+ final File file = File.createTempFile("ExpectedIOTest", ".tmp");
+ final int LOOPS = 30;
+
+ Thread producer = new Thread("PRODUCER")
+ {
+ @Override
+ public void run()
+ {
+ DataOutputStream out = null;
+
+ try
+ {
+ out = new DataOutputStream(new FileOutputStream(file));
+ for (int i = 0; i < LOOPS; i++)
+ {
+ out.writeInt(i);
+ IOUtil.ERR().println(i);
+ ConcurrencyUtil.sleep(100);
+ }
+ }
+ catch (Exception ex)
+ {
+ if (exception == null)
+ {
+ exception = ex;
+ }
+ }
+ finally
+ {
+ IOUtil.close(out);
+ }
+ }
+ };
+
+ Thread consumer = new Thread("CONSUMER")
+ {
+ @Override
+ public void run()
+ {
+ DataInputStream in = null;
+
+ try
+ {
+ in = new DataInputStream(new ExpectedFileInputStream(file, LOOPS * 4));
+
+ for (int i = 0; i < LOOPS + 10; i++)
+ {
+ System.out.println(in.readInt());
+ }
+ }
+ catch (Exception ex)
+ {
+ if (exception == null)
+ {
+ exception = ex;
+ }
+ }
+ finally
+ {
+ IOUtil.close(in);
+ }
+ }
+ };
+
+ producer.start();
+ ConcurrencyUtil.sleep(500);
+ consumer.start();
+
+ producer.join();
+ consumer.join();
+
+ if (!(exception instanceof EOFException))
+ {
+ throw exception;
+ }
+ }
+
+ public void testReader() throws Exception
+ {
+ final File file = File.createTempFile("ExpectedIOTest", ".tmp");
+ final int LOOPS = 30;
+
+ Thread producer = new Thread("PRODUCER")
+ {
+ @Override
+ public void run()
+ {
+ Writer out = null;
+
+ try
+ {
+ out = new FileWriter(file);
+ for (int i = 0; i < LOOPS; i++)
+ {
+ int c = 'a' + i;
+ out.write(c);
+ IOUtil.ERR().println(c);
+
+ out.write(c + 1);
+ IOUtil.ERR().println(c + 1);
+ ConcurrencyUtil.sleep(100);
+ }
+ }
+ catch (Exception ex)
+ {
+ if (exception == null)
+ {
+ exception = ex;
+ }
+ }
+ finally
+ {
+ IOUtil.close(out);
+ }
+ }
+ };
+
+ Thread consumer = new Thread("CONSUMER")
+ {
+ @Override
+ public void run()
+ {
+ Reader in = null;
+
+ try
+ {
+ in = new ExpectedFileReader(file, LOOPS * 2);
+
+ for (int i = 0; i < LOOPS; i++)
+ {
+ int c = in.read();
+ if (c == -1)
+ {
+ throw new EOFException();
+ }
+
+ System.out.println(c);
+ c = in.read();
+ if (c == -1)
+ {
+ throw new EOFException();
+ }
+
+ System.out.println(c);
+ }
+ }
+ catch (Exception ex)
+ {
+ if (exception == null)
+ {
+ exception = ex;
+ }
+ }
+ finally
+ {
+ IOUtil.close(in);
+ }
+ }
+ };
+
+ producer.start();
+ ConcurrencyUtil.sleep(500);
+ consumer.start();
+
+ producer.join();
+ consumer.join();
+
+ if (exception != null)
+ {
+ throw exception;
+ }
+ }
+
+ public void testReaderEOF() throws Exception
+ {
+ final File file = File.createTempFile("ExpectedIOTest", ".tmp");
+ final int LOOPS = 30;
+
+ Thread producer = new Thread("PRODUCER")
+ {
+ @Override
+ public void run()
+ {
+ Writer out = null;
+
+ try
+ {
+ out = new FileWriter(file);
+ for (int i = 0; i < LOOPS; i++)
+ {
+ int c = 'a' + i;
+ out.write(c);
+ IOUtil.ERR().println(c);
+
+ out.write(c + 1);
+ IOUtil.ERR().println(c + 1);
+ ConcurrencyUtil.sleep(100);
+ }
+ }
+ catch (Exception ex)
+ {
+ if (exception == null)
+ {
+ exception = ex;
+ }
+ }
+ finally
+ {
+ IOUtil.close(out);
+ }
+ }
+ };
+
+ Thread consumer = new Thread("CONSUMER")
+ {
+ @Override
+ public void run()
+ {
+ Reader in = null;
+
+ try
+ {
+ in = new ExpectedFileReader(file, LOOPS * 2);
+
+ for (int i = 0; i < LOOPS + 10; i++)
+ {
+ int c = in.read();
+ if (c == -1)
+ {
+ throw new EOFException();
+ }
+
+ System.out.println(c);
+ c = in.read();
+ if (c == -1)
+ {
+ throw new EOFException();
+ }
+
+ System.out.println(c);
+ }
+ }
+ catch (Exception ex)
+ {
+ if (exception == null)
+ {
+ exception = ex;
+ }
+ }
+ finally
+ {
+ IOUtil.close(in);
+ }
+ }
+ };
+
+ producer.start();
+ ConcurrencyUtil.sleep(500);
+ consumer.start();
+
+ producer.join();
+ consumer.join();
+
+ if (!(exception instanceof EOFException))
+ {
+ throw exception;
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/ExtendedIOTest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/ExtendedIOTest.java
index f2ab8c34e3..854e9521ad 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/ExtendedIOTest.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/ExtendedIOTest.java
@@ -1,157 +1,157 @@
-/*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- */
-package org.eclipse.net4j.util.tests;
-
-import org.eclipse.net4j.util.io.ExtendedDataInputStream;
-import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.HashMap;
-
-/**
- * @author Eike Stepper
- */
-public class ExtendedIOTest extends AbstractOMTest
-{
- @SuppressWarnings("unchecked")
- public void testObject() throws Exception
- {
- final HashMap<String, String> map = createMap();
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ExtendedDataOutputStream edos = new ExtendedDataOutputStream(baos);
- edos.writeObject(map);
- edos.close();
-
- ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
- ExtendedDataInputStream edis = new ExtendedDataInputStream(bais);
- HashMap<String, String> result = (HashMap<String, String>)edis.readObject();
- assertEquals(map, result);
- }
-
- public void testObject1() throws Exception
- {
- final byte[] byteArray = createByteArray1();
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ExtendedDataOutputStream edos = new ExtendedDataOutputStream(baos);
- edos.writeObject(byteArray);
- edos.close();
-
- ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
- ExtendedDataInputStream edis = new ExtendedDataInputStream(bais);
- byte[] result = (byte[])edis.readObject();
- assertEquals(true, Arrays.equals(byteArray, result));
- }
-
- public void testObject2() throws Exception
- {
- final byte[] byteArray = createByteArray2();
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ExtendedDataOutputStream edos = new ExtendedDataOutputStream(baos);
- edos.writeObject(byteArray);
- edos.close();
-
- ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
- ExtendedDataInputStream edis = new ExtendedDataInputStream(bais);
- byte[] result = (byte[])edis.readObject();
- assertEquals(true, Arrays.equals(byteArray, result));
- }
-
- public void testByteArray1() throws Exception
- {
- final byte[] byteArray = createByteArray1();
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ExtendedDataOutputStream edos = new ExtendedDataOutputStream(baos);
- edos.writeByteArray(byteArray);
- edos.close();
-
- ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
- ExtendedDataInputStream edis = new ExtendedDataInputStream(bais);
- byte[] result = edis.readByteArray();
- assertEquals(true, Arrays.equals(byteArray, result));
- }
-
- public void testByteArray2() throws Exception
- {
- final byte[] byteArray = createByteArray2();
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ExtendedDataOutputStream edos = new ExtendedDataOutputStream(baos);
- edos.writeByteArray(byteArray);
- edos.close();
-
- ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
- ExtendedDataInputStream edis = new ExtendedDataInputStream(bais);
- byte[] result = edis.readByteArray();
- assertEquals(true, Arrays.equals(byteArray, result));
- }
-
- private byte[] createByteArray1() throws IOException
- {
- HashMap<String, String> map = createMap();
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ExtendedDataOutputStream edos = new ExtendedDataOutputStream(baos);
- edos.writeObject(map);
- edos.close();
- return baos.toByteArray();
- }
-
- private byte[] createByteArray2()
- {
- byte[] byteArray = new byte[256];
- byte v = Byte.MIN_VALUE;
- for (int i = 0; i < byteArray.length; i++)
- {
- byteArray[i] = v++;
- }
-
- return byteArray;
- }
-
- private HashMap<String, String> createMap()
- {
- HashMap<String, String> map = new HashMap<String, String>();
- putMap(map, "org.eclipse.net4j.util.io.CachedFileMap.java"); //$NON-NLS-1$
- putMap(map, "org.eclipse.net4j.util.io.CloseableIterator.java"); //$NON-NLS-1$
- putMap(map, "org.eclipse.net4j.util.io.DataInputExtender.java"); //$NON-NLS-1$
- putMap(map, "org.eclipse.net4j.util.io.DataOutputExtender.java"); //$NON-NLS-1$
- putMap(map, "org.eclipse.net4j.util.io.DelegatingInputStream.java"); //$NON-NLS-1$
- putMap(map, "org.eclipse.net4j.util.io.DelegatingOutputStream.java"); //$NON-NLS-1$
- putMap(map, "org.eclipse.net4j.util.io.DelegatingStreamWrapper.java"); //$NON-NLS-1$
- putMap(map, "org.eclipse.net4j.util.io.ExtendedDataInput.java"); //$NON-NLS-1$
- putMap(map, "org.eclipse.net4j.util.io.ExtendedDataInputStream.java"); //$NON-NLS-1$
- putMap(map, "org.eclipse.net4j.util.io.ExtendedDataOutput.java"); //$NON-NLS-1$
- putMap(map, "org.eclipse.net4j.util.io.ExtendedDataOutputStream.java"); //$NON-NLS-1$
- putMap(map, "org.eclipse.net4j.util.io.ExtendedIOUtil.java"); //$NON-NLS-1$
- putMap(map, "org.eclipse.net4j.util.io.GZIPStreamWrapper.java"); //$NON-NLS-1$
- putMap(map, "org.eclipse.net4j.util.io.IOFilter.java"); //$NON-NLS-1$
- putMap(map, "org.eclipse.net4j.util.io.IORunnable.java"); //$NON-NLS-1$
- putMap(map, "org.eclipse.net4j.util.io.IORuntimeException.java"); //$NON-NLS-1$
- putMap(map, "org.eclipse.net4j.util.io.IOUtil.java"); //$NON-NLS-1$
- putMap(map, "org.eclipse.net4j.util.io.IOVisitor.java"); //$NON-NLS-1$
- putMap(map, "org.eclipse.net4j.util.io.IStreamWrapper.java"); //$NON-NLS-1$
- putMap(map, "org.eclipse.net4j.util.io.NIOUtil.java"); //$NON-NLS-1$
- putMap(map, "org.eclipse.net4j.util.io.SortedFileMap.java"); //$NON-NLS-1$
- putMap(map, "org.eclipse.net4j.util.io.StreamWrapperChain.java"); //$NON-NLS-1$
- putMap(map, "org.eclipse.net4j.util.io.TMPUtil.java"); //$NON-NLS-1$
- putMap(map, "org.eclipse.net4j.util.io.XORInputStream.java"); //$NON-NLS-1$
- putMap(map, "org.eclipse.net4j.util.io.XOROutputStream.java"); //$NON-NLS-1$
- putMap(map, "org.eclipse.net4j.util.io.XORStreamWrapper.java"); //$NON-NLS-1$
- putMap(map, "org.eclipse.net4j.util.io.ZIPUtil.java"); //$NON-NLS-1$
- return map;
- }
-
- private void putMap(HashMap<String, String> map, String string)
- {
- map.put(string, string);
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.util.tests;
+
+import org.eclipse.net4j.util.io.ExtendedDataInputStream;
+import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.HashMap;
+
+/**
+ * @author Eike Stepper
+ */
+public class ExtendedIOTest extends AbstractOMTest
+{
+ @SuppressWarnings("unchecked")
+ public void testObject() throws Exception
+ {
+ final HashMap<String, String> map = createMap();
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ExtendedDataOutputStream edos = new ExtendedDataOutputStream(baos);
+ edos.writeObject(map);
+ edos.close();
+
+ ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+ ExtendedDataInputStream edis = new ExtendedDataInputStream(bais);
+ HashMap<String, String> result = (HashMap<String, String>)edis.readObject();
+ assertEquals(map, result);
+ }
+
+ public void testObject1() throws Exception
+ {
+ final byte[] byteArray = createByteArray1();
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ExtendedDataOutputStream edos = new ExtendedDataOutputStream(baos);
+ edos.writeObject(byteArray);
+ edos.close();
+
+ ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+ ExtendedDataInputStream edis = new ExtendedDataInputStream(bais);
+ byte[] result = (byte[])edis.readObject();
+ assertEquals(true, Arrays.equals(byteArray, result));
+ }
+
+ public void testObject2() throws Exception
+ {
+ final byte[] byteArray = createByteArray2();
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ExtendedDataOutputStream edos = new ExtendedDataOutputStream(baos);
+ edos.writeObject(byteArray);
+ edos.close();
+
+ ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+ ExtendedDataInputStream edis = new ExtendedDataInputStream(bais);
+ byte[] result = (byte[])edis.readObject();
+ assertEquals(true, Arrays.equals(byteArray, result));
+ }
+
+ public void testByteArray1() throws Exception
+ {
+ final byte[] byteArray = createByteArray1();
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ExtendedDataOutputStream edos = new ExtendedDataOutputStream(baos);
+ edos.writeByteArray(byteArray);
+ edos.close();
+
+ ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+ ExtendedDataInputStream edis = new ExtendedDataInputStream(bais);
+ byte[] result = edis.readByteArray();
+ assertEquals(true, Arrays.equals(byteArray, result));
+ }
+
+ public void testByteArray2() throws Exception
+ {
+ final byte[] byteArray = createByteArray2();
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ExtendedDataOutputStream edos = new ExtendedDataOutputStream(baos);
+ edos.writeByteArray(byteArray);
+ edos.close();
+
+ ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+ ExtendedDataInputStream edis = new ExtendedDataInputStream(bais);
+ byte[] result = edis.readByteArray();
+ assertEquals(true, Arrays.equals(byteArray, result));
+ }
+
+ private byte[] createByteArray1() throws IOException
+ {
+ HashMap<String, String> map = createMap();
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ExtendedDataOutputStream edos = new ExtendedDataOutputStream(baos);
+ edos.writeObject(map);
+ edos.close();
+ return baos.toByteArray();
+ }
+
+ private byte[] createByteArray2()
+ {
+ byte[] byteArray = new byte[256];
+ byte v = Byte.MIN_VALUE;
+ for (int i = 0; i < byteArray.length; i++)
+ {
+ byteArray[i] = v++;
+ }
+
+ return byteArray;
+ }
+
+ private HashMap<String, String> createMap()
+ {
+ HashMap<String, String> map = new HashMap<String, String>();
+ putMap(map, "org.eclipse.net4j.util.io.CachedFileMap.java"); //$NON-NLS-1$
+ putMap(map, "org.eclipse.net4j.util.io.CloseableIterator.java"); //$NON-NLS-1$
+ putMap(map, "org.eclipse.net4j.util.io.DataInputExtender.java"); //$NON-NLS-1$
+ putMap(map, "org.eclipse.net4j.util.io.DataOutputExtender.java"); //$NON-NLS-1$
+ putMap(map, "org.eclipse.net4j.util.io.DelegatingInputStream.java"); //$NON-NLS-1$
+ putMap(map, "org.eclipse.net4j.util.io.DelegatingOutputStream.java"); //$NON-NLS-1$
+ putMap(map, "org.eclipse.net4j.util.io.DelegatingStreamWrapper.java"); //$NON-NLS-1$
+ putMap(map, "org.eclipse.net4j.util.io.ExtendedDataInput.java"); //$NON-NLS-1$
+ putMap(map, "org.eclipse.net4j.util.io.ExtendedDataInputStream.java"); //$NON-NLS-1$
+ putMap(map, "org.eclipse.net4j.util.io.ExtendedDataOutput.java"); //$NON-NLS-1$
+ putMap(map, "org.eclipse.net4j.util.io.ExtendedDataOutputStream.java"); //$NON-NLS-1$
+ putMap(map, "org.eclipse.net4j.util.io.ExtendedIOUtil.java"); //$NON-NLS-1$
+ putMap(map, "org.eclipse.net4j.util.io.GZIPStreamWrapper.java"); //$NON-NLS-1$
+ putMap(map, "org.eclipse.net4j.util.io.IOFilter.java"); //$NON-NLS-1$
+ putMap(map, "org.eclipse.net4j.util.io.IORunnable.java"); //$NON-NLS-1$
+ putMap(map, "org.eclipse.net4j.util.io.IORuntimeException.java"); //$NON-NLS-1$
+ putMap(map, "org.eclipse.net4j.util.io.IOUtil.java"); //$NON-NLS-1$
+ putMap(map, "org.eclipse.net4j.util.io.IOVisitor.java"); //$NON-NLS-1$
+ putMap(map, "org.eclipse.net4j.util.io.IStreamWrapper.java"); //$NON-NLS-1$
+ putMap(map, "org.eclipse.net4j.util.io.NIOUtil.java"); //$NON-NLS-1$
+ putMap(map, "org.eclipse.net4j.util.io.SortedFileMap.java"); //$NON-NLS-1$
+ putMap(map, "org.eclipse.net4j.util.io.StreamWrapperChain.java"); //$NON-NLS-1$
+ putMap(map, "org.eclipse.net4j.util.io.TMPUtil.java"); //$NON-NLS-1$
+ putMap(map, "org.eclipse.net4j.util.io.XORInputStream.java"); //$NON-NLS-1$
+ putMap(map, "org.eclipse.net4j.util.io.XOROutputStream.java"); //$NON-NLS-1$
+ putMap(map, "org.eclipse.net4j.util.io.XORStreamWrapper.java"); //$NON-NLS-1$
+ putMap(map, "org.eclipse.net4j.util.io.ZIPUtil.java"); //$NON-NLS-1$
+ return map;
+ }
+
+ private void putMap(HashMap<String, String> map, String string)
+ {
+ map.put(string, string);
+ }
+}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/FastListTest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/FastListTest.java
index 0f7f24d9f7..495f927042 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/FastListTest.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/FastListTest.java
@@ -1,294 +1,294 @@
-/*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- * Caspar De Groot - maintenance
- */
-package org.eclipse.net4j.util.tests;
-
-import org.eclipse.net4j.util.collection.ConcurrentArray;
-
-/**
- * @author Eike Stepper
- * @since 3.1
- */
-public class FastListTest extends AbstractOMTest
-{
- public static void testAddFirst() throws Exception
- {
- TestList list = new TestList();
- list.add(5);
-
- Integer[] result = list.get();
- assertEquals(true, result != null);
- assertEquals(true, result.length == 1);
- assertEquals(true, list.getElements().length == 1);
- assertEquals(true, !list.isEmpty());
- assertEquals(true, list.added == 1);
- assertEquals(true, list.removed == 0);
- }
-
- public static void testAddSecond() throws Exception
- {
- TestList list = new TestList();
- list.add(5);
- list.add(7);
-
- Integer[] result = list.get();
- assertEquals(true, result != null);
- assertEquals(true, result.length == 2);
- assertEquals(true, list.getElements().length == 2);
- assertEquals(true, !list.isEmpty());
- assertEquals(true, list.added == 1);
- assertEquals(true, list.removed == 0);
- }
-
- public static void testRemoveHead() throws Exception
- {
- TestList list = new TestList();
- list.add(5);
- list.add(7);
- list.add(2);
- list.add(9);
- list.add(1);
- list.add(4);
- list.add(8);
-
- Integer[] old = list.reset();
- boolean removed = list.remove(5);
-
- Integer[] result = list.get();
- assertEquals(true, removed);
- assertEquals(true, result != null);
- assertEquals(true, result != old);
- assertEquals(true, result.length == 6);
- assertEquals(true, list.getElements().length == 6);
- assertEquals(true, !list.isEmpty());
- assertEquals(true, list.added == 0);
- assertEquals(true, list.removed == 0);
- assertEquals(true, result[0] == 7);
- assertEquals(true, result[1] == 2);
- assertEquals(true, result[2] == 9);
- assertEquals(true, result[3] == 1);
- assertEquals(true, result[4] == 4);
- assertEquals(true, result[5] == 8);
- }
-
- public static void testRemoveMiddle() throws Exception
- {
- TestList list = new TestList();
- list.add(5);
- list.add(7);
- list.add(2);
- list.add(9);
- list.add(1);
- list.add(4);
- list.add(8);
-
- Integer[] old = list.reset();
- boolean removed = list.remove(9);
-
- Integer[] result = list.get();
- assertEquals(true, removed);
- assertEquals(true, result != null);
- assertEquals(true, result != old);
- assertEquals(true, result.length == 6);
- assertEquals(true, list.getElements().length == 6);
- assertEquals(true, !list.isEmpty());
- assertEquals(true, list.added == 0);
- assertEquals(true, list.removed == 0);
- assertEquals(true, result[0] == 5);
- assertEquals(true, result[1] == 7);
- assertEquals(true, result[2] == 2);
- assertEquals(true, result[3] == 1);
- assertEquals(true, result[4] == 4);
- assertEquals(true, result[5] == 8);
- }
-
- public void testRemoveMiddleOfThree()
- {
- TestList list = new TestList();
- Integer one = new Integer(1);
- Integer two = new Integer(2);
- Integer three = new Integer(3);
-
- list.add(one);
- list.add(two);
- list.add(three);
-
- list.remove(two);
-
- Integer[] elements = list.get();
- assertSame(one, elements[0]);
- assertSame(three, elements[1]);
- }
-
- public static void testRemoveTail() throws Exception
- {
- TestList list = new TestList();
- list.add(5);
- list.add(7);
- list.add(2);
- list.add(9);
- list.add(1);
- list.add(4);
- list.add(8);
-
- Integer[] old = list.reset();
- boolean removed = list.remove(8);
-
- Integer[] result = list.get();
- assertEquals(true, removed);
- assertEquals(true, result != old);
- assertEquals(true, result != null);
- assertEquals(true, result.length == 6);
- assertEquals(true, list.getElements().length == 6);
- assertEquals(true, !list.isEmpty());
- assertEquals(true, list.added == 0);
- assertEquals(true, list.removed == 0);
- assertEquals(true, result[0] == 5);
- assertEquals(true, result[1] == 7);
- assertEquals(true, result[2] == 2);
- assertEquals(true, result[3] == 9);
- assertEquals(true, result[4] == 1);
- assertEquals(true, result[5] == 4);
- }
-
- public static void testRemoveLast() throws Exception
- {
- TestList list = new TestList();
- list.add(5);
- list.add(7);
-
- Integer[] old = list.reset();
- boolean removed1 = list.remove(7);
- boolean removed2 = list.remove(5);
-
- Integer[] result = list.get();
- assertEquals(true, removed1);
- assertEquals(true, removed2);
- assertEquals(true, result != old);
- assertEquals(true, result == null);
- assertEquals(true, list.getElements() == null);
- assertEquals(true, list.isEmpty());
- assertEquals(true, list.added == 0);
- assertEquals(true, list.removed == 1);
- }
-
- public static void testNotFoundInMany() throws Exception
- {
- TestList list = new TestList();
- list.add(5);
- list.add(7);
- list.add(2);
- list.add(9);
- list.add(1);
- list.add(4);
- list.add(8);
-
- Integer[] old = list.reset();
- boolean removed = list.remove(10);
-
- Integer[] result = list.get();
- assertEquals(true, !removed);
- assertEquals(true, result != null);
- assertEquals(true, result == old);
- assertEquals(true, result.length == 7);
- assertEquals(true, list.getElements().length == 7);
- assertEquals(true, !list.isEmpty());
- assertEquals(true, list.added == 0);
- assertEquals(true, list.removed == 0);
- assertEquals(true, result[0] == 5);
- assertEquals(true, result[1] == 7);
- assertEquals(true, result[2] == 2);
- assertEquals(true, result[3] == 9);
- assertEquals(true, result[4] == 1);
- assertEquals(true, result[5] == 4);
- assertEquals(true, result[6] == 8);
- }
-
- public static void testNotFoundInOne() throws Exception
- {
- TestList list = new TestList();
- list.add(5);
-
- Integer[] old = list.reset();
- boolean removed = list.remove(10);
-
- Integer[] result = list.get();
- assertEquals(true, !removed);
- assertEquals(true, result != null);
- assertEquals(true, result == old);
- assertEquals(true, result.length == 1);
- assertEquals(true, list.getElements().length == 1);
- assertEquals(true, !list.isEmpty());
- assertEquals(true, list.added == 0);
- assertEquals(true, list.removed == 0);
- assertEquals(true, result[0] == 5);
- }
-
- public static void testNotFoundInEmpty() throws Exception
- {
- TestList list = new TestList();
-
- Integer[] old = list.reset();
- boolean removed = list.remove(10);
-
- Integer[] result = list.get();
- assertEquals(true, !removed);
- assertEquals(true, result == null);
- assertEquals(true, result == old);
- assertEquals(true, list.isEmpty());
- assertEquals(true, list.added == 0);
- assertEquals(true, list.removed == 0);
- }
-
- /**
- * @author Eike Stepper
- */
- public static class TestList extends ConcurrentArray<Integer>
- {
- public int added;
-
- public int removed;
-
- public TestList()
- {
- }
-
- public Integer[] getElements()
- {
- return elements;
- }
-
- public Integer[] reset()
- {
- added = 0;
- removed = 0;
- return elements;
- }
-
- @Override
- protected Integer[] newArray(int length)
- {
- return new Integer[length];
- }
-
- @Override
- protected void firstElementAdded()
- {
- ++added;
- }
-
- @Override
- protected void lastElementRemoved()
- {
- ++removed;
- }
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ * Caspar De Groot - maintenance
+ */
+package org.eclipse.net4j.util.tests;
+
+import org.eclipse.net4j.util.collection.ConcurrentArray;
+
+/**
+ * @author Eike Stepper
+ * @since 3.1
+ */
+public class FastListTest extends AbstractOMTest
+{
+ public static void testAddFirst() throws Exception
+ {
+ TestList list = new TestList();
+ list.add(5);
+
+ Integer[] result = list.get();
+ assertEquals(true, result != null);
+ assertEquals(true, result.length == 1);
+ assertEquals(true, list.getElements().length == 1);
+ assertEquals(true, !list.isEmpty());
+ assertEquals(true, list.added == 1);
+ assertEquals(true, list.removed == 0);
+ }
+
+ public static void testAddSecond() throws Exception
+ {
+ TestList list = new TestList();
+ list.add(5);
+ list.add(7);
+
+ Integer[] result = list.get();
+ assertEquals(true, result != null);
+ assertEquals(true, result.length == 2);
+ assertEquals(true, list.getElements().length == 2);
+ assertEquals(true, !list.isEmpty());
+ assertEquals(true, list.added == 1);
+ assertEquals(true, list.removed == 0);
+ }
+
+ public static void testRemoveHead() throws Exception
+ {
+ TestList list = new TestList();
+ list.add(5);
+ list.add(7);
+ list.add(2);
+ list.add(9);
+ list.add(1);
+ list.add(4);
+ list.add(8);
+
+ Integer[] old = list.reset();
+ boolean removed = list.remove(5);
+
+ Integer[] result = list.get();
+ assertEquals(true, removed);
+ assertEquals(true, result != null);
+ assertEquals(true, result != old);
+ assertEquals(true, result.length == 6);
+ assertEquals(true, list.getElements().length == 6);
+ assertEquals(true, !list.isEmpty());
+ assertEquals(true, list.added == 0);
+ assertEquals(true, list.removed == 0);
+ assertEquals(true, result[0] == 7);
+ assertEquals(true, result[1] == 2);
+ assertEquals(true, result[2] == 9);
+ assertEquals(true, result[3] == 1);
+ assertEquals(true, result[4] == 4);
+ assertEquals(true, result[5] == 8);
+ }
+
+ public static void testRemoveMiddle() throws Exception
+ {
+ TestList list = new TestList();
+ list.add(5);
+ list.add(7);
+ list.add(2);
+ list.add(9);
+ list.add(1);
+ list.add(4);
+ list.add(8);
+
+ Integer[] old = list.reset();
+ boolean removed = list.remove(9);
+
+ Integer[] result = list.get();
+ assertEquals(true, removed);
+ assertEquals(true, result != null);
+ assertEquals(true, result != old);
+ assertEquals(true, result.length == 6);
+ assertEquals(true, list.getElements().length == 6);
+ assertEquals(true, !list.isEmpty());
+ assertEquals(true, list.added == 0);
+ assertEquals(true, list.removed == 0);
+ assertEquals(true, result[0] == 5);
+ assertEquals(true, result[1] == 7);
+ assertEquals(true, result[2] == 2);
+ assertEquals(true, result[3] == 1);
+ assertEquals(true, result[4] == 4);
+ assertEquals(true, result[5] == 8);
+ }
+
+ public void testRemoveMiddleOfThree()
+ {
+ TestList list = new TestList();
+ Integer one = new Integer(1);
+ Integer two = new Integer(2);
+ Integer three = new Integer(3);
+
+ list.add(one);
+ list.add(two);
+ list.add(three);
+
+ list.remove(two);
+
+ Integer[] elements = list.get();
+ assertSame(one, elements[0]);
+ assertSame(three, elements[1]);
+ }
+
+ public static void testRemoveTail() throws Exception
+ {
+ TestList list = new TestList();
+ list.add(5);
+ list.add(7);
+ list.add(2);
+ list.add(9);
+ list.add(1);
+ list.add(4);
+ list.add(8);
+
+ Integer[] old = list.reset();
+ boolean removed = list.remove(8);
+
+ Integer[] result = list.get();
+ assertEquals(true, removed);
+ assertEquals(true, result != old);
+ assertEquals(true, result != null);
+ assertEquals(true, result.length == 6);
+ assertEquals(true, list.getElements().length == 6);
+ assertEquals(true, !list.isEmpty());
+ assertEquals(true, list.added == 0);
+ assertEquals(true, list.removed == 0);
+ assertEquals(true, result[0] == 5);
+ assertEquals(true, result[1] == 7);
+ assertEquals(true, result[2] == 2);
+ assertEquals(true, result[3] == 9);
+ assertEquals(true, result[4] == 1);
+ assertEquals(true, result[5] == 4);
+ }
+
+ public static void testRemoveLast() throws Exception
+ {
+ TestList list = new TestList();
+ list.add(5);
+ list.add(7);
+
+ Integer[] old = list.reset();
+ boolean removed1 = list.remove(7);
+ boolean removed2 = list.remove(5);
+
+ Integer[] result = list.get();
+ assertEquals(true, removed1);
+ assertEquals(true, removed2);
+ assertEquals(true, result != old);
+ assertEquals(true, result == null);
+ assertEquals(true, list.getElements() == null);
+ assertEquals(true, list.isEmpty());
+ assertEquals(true, list.added == 0);
+ assertEquals(true, list.removed == 1);
+ }
+
+ public static void testNotFoundInMany() throws Exception
+ {
+ TestList list = new TestList();
+ list.add(5);
+ list.add(7);
+ list.add(2);
+ list.add(9);
+ list.add(1);
+ list.add(4);
+ list.add(8);
+
+ Integer[] old = list.reset();
+ boolean removed = list.remove(10);
+
+ Integer[] result = list.get();
+ assertEquals(true, !removed);
+ assertEquals(true, result != null);
+ assertEquals(true, result == old);
+ assertEquals(true, result.length == 7);
+ assertEquals(true, list.getElements().length == 7);
+ assertEquals(true, !list.isEmpty());
+ assertEquals(true, list.added == 0);
+ assertEquals(true, list.removed == 0);
+ assertEquals(true, result[0] == 5);
+ assertEquals(true, result[1] == 7);
+ assertEquals(true, result[2] == 2);
+ assertEquals(true, result[3] == 9);
+ assertEquals(true, result[4] == 1);
+ assertEquals(true, result[5] == 4);
+ assertEquals(true, result[6] == 8);
+ }
+
+ public static void testNotFoundInOne() throws Exception
+ {
+ TestList list = new TestList();
+ list.add(5);
+
+ Integer[] old = list.reset();
+ boolean removed = list.remove(10);
+
+ Integer[] result = list.get();
+ assertEquals(true, !removed);
+ assertEquals(true, result != null);
+ assertEquals(true, result == old);
+ assertEquals(true, result.length == 1);
+ assertEquals(true, list.getElements().length == 1);
+ assertEquals(true, !list.isEmpty());
+ assertEquals(true, list.added == 0);
+ assertEquals(true, list.removed == 0);
+ assertEquals(true, result[0] == 5);
+ }
+
+ public static void testNotFoundInEmpty() throws Exception
+ {
+ TestList list = new TestList();
+
+ Integer[] old = list.reset();
+ boolean removed = list.remove(10);
+
+ Integer[] result = list.get();
+ assertEquals(true, !removed);
+ assertEquals(true, result == null);
+ assertEquals(true, result == old);
+ assertEquals(true, list.isEmpty());
+ assertEquals(true, list.added == 0);
+ assertEquals(true, list.removed == 0);
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static class TestList extends ConcurrentArray<Integer>
+ {
+ public int added;
+
+ public int removed;
+
+ public TestList()
+ {
+ }
+
+ public Integer[] getElements()
+ {
+ return elements;
+ }
+
+ public Integer[] reset()
+ {
+ added = 0;
+ removed = 0;
+ return elements;
+ }
+
+ @Override
+ protected Integer[] newArray(int length)
+ {
+ return new Integer[length];
+ }
+
+ @Override
+ protected void firstElementAdded()
+ {
+ ++added;
+ }
+
+ @Override
+ protected void lastElementRemoved()
+ {
+ ++removed;
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/MonitorTest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/MonitorTest.java
index ba1844a173..6ed7971120 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/MonitorTest.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/MonitorTest.java
@@ -1,302 +1,302 @@
-/*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- */
-package org.eclipse.net4j.util.tests;
-
-import org.eclipse.net4j.util.om.monitor.Monitor;
-import org.eclipse.net4j.util.om.monitor.OMMonitor;
-import org.eclipse.net4j.util.om.monitor.OMMonitor.Async;
-
-/**
- * @author Eike Stepper
- */
-public class MonitorTest extends AbstractOMTest
-{
- public void testBeginNotCalledOnMonitor() throws Exception
- {
- try
- {
- OMMonitor monitor = new Monitor();
- monitor.worked();
- fail("IllegalStateException expected"); //$NON-NLS-1$
- }
- catch (IllegalStateException ex)
- {
- // Success
- }
-
- try
- {
- OMMonitor monitor = new Monitor();
- monitor.fork();
- fail("IllegalStateException expected"); //$NON-NLS-1$
- }
- catch (IllegalStateException ex)
- {
- // Success
- }
-
- Async async = null;
- try
- {
- OMMonitor monitor = new Monitor();
- async = monitor.forkAsync();
- fail("IllegalStateException expected"); //$NON-NLS-1$
- }
- catch (IllegalStateException ex)
- {
- // Success
- }
- finally
- {
- if (async != null)
- {
- async.stop();
- }
- }
- }
-
- public void testBeginNotCalledOnNestedMonitor() throws Exception
- {
- try
- {
- OMMonitor monitor = new Monitor().begin().fork();
- monitor.worked();
- fail("IllegalStateException expected"); //$NON-NLS-1$
- }
- catch (IllegalStateException ex)
- {
- // Success
- }
-
- try
- {
- OMMonitor monitor = new Monitor().begin().fork();
- monitor.fork();
- fail("IllegalStateException expected"); //$NON-NLS-1$
- }
- catch (IllegalStateException ex)
- {
- // Success
- }
-
- Async async = null;
- try
- {
- OMMonitor monitor = new Monitor().begin().fork();
- async = monitor.forkAsync();
- fail("IllegalStateException expected"); //$NON-NLS-1$
- }
- catch (IllegalStateException ex)
- {
- // Success
- }
- finally
- {
- if (async != null)
- {
- async.stop();
- }
- }
- }
-
- public void testBeginCalledOnMonitor() throws Exception
- {
- {
- OMMonitor monitor = new Monitor().begin();
- monitor.worked();
- }
-
- {
- OMMonitor monitor = new Monitor().begin();
- monitor.fork();
- }
-
- Async async = null;
- try
- {
- OMMonitor monitor = new Monitor().begin();
- async = monitor.forkAsync();
- }
- finally
- {
- if (async != null)
- {
- async.stop();
- }
- }
- }
-
- public void testBeginCalledOnNestedMonitor() throws Exception
- {
- {
- OMMonitor monitor = new Monitor().begin().fork().begin();
- monitor.worked();
- }
-
- {
- OMMonitor monitor = new Monitor().begin().fork().begin();
- monitor.fork();
- }
-
- Async async = null;
- try
- {
- OMMonitor monitor = new Monitor().begin().fork().begin();
- async = monitor.forkAsync();
- }
- finally
- {
- if (async != null)
- {
- async.stop();
- }
- }
- }
-
- public void testProgress() throws Exception
- {
- // Worked completely
- {
- OMMonitor monitor = new Monitor();
- assertNotSame(OMMonitor.ZERO, monitor.getTotalWork());
- assertEquals(OMMonitor.ZERO, monitor.getWork());
-
- monitor.begin(OMMonitor.TEN);
- assertEquals(OMMonitor.TEN, monitor.getTotalWork());
- assertEquals(OMMonitor.ZERO, monitor.getWork());
-
- for (int i = 0; i < 10; i++)
- {
- monitor.worked();
- assertEquals(OMMonitor.TEN, monitor.getTotalWork());
- assertEquals((double)i + 1, monitor.getWork());
- }
-
- monitor.done();
- assertEquals(OMMonitor.TEN, monitor.getTotalWork());
- assertEquals(monitor.getTotalWork(), monitor.getWork());
- }
-
- // Worked incompletely
- {
- OMMonitor monitor = new Monitor();
- assertNotSame(OMMonitor.ZERO, monitor.getTotalWork());
- assertEquals(OMMonitor.ZERO, monitor.getWork());
-
- monitor.begin(OMMonitor.TEN);
- assertEquals(OMMonitor.TEN, monitor.getTotalWork());
- assertEquals(OMMonitor.ZERO, monitor.getWork());
-
- for (int i = 0; i < 5; i++)
- {
- monitor.worked();
- assertEquals(OMMonitor.TEN, monitor.getTotalWork());
- assertEquals((double)i + 1, monitor.getWork());
- }
-
- monitor.done();
- assertEquals(OMMonitor.TEN, monitor.getTotalWork());
- assertEquals(monitor.getTotalWork(), monitor.getWork());
- }
- }
-
- public void testNestedProgress() throws Exception
- {
- // Worked completely
- {
- OMMonitor main = new Monitor().begin();
- assertEquals(OMMonitor.ONE, main.getTotalWork());
-
- OMMonitor monitor = main.fork();
- assertNotSame(OMMonitor.ZERO, monitor.getTotalWork());
- assertEquals(OMMonitor.ZERO, monitor.getWork());
-
- monitor.begin(OMMonitor.TEN);
- assertEquals(OMMonitor.TEN, monitor.getTotalWork());
- assertEquals(OMMonitor.ZERO, monitor.getWork());
-
- for (int i = 0; i < 10; i++)
- {
- monitor.worked();
- assertEquals(OMMonitor.TEN, monitor.getTotalWork());
- assertEquals((double)i + 1, monitor.getWork());
- assertSimilar(OMMonitor.ONE / OMMonitor.TEN * (i + 1), main.getWork(), 1000);
- }
-
- monitor.done();
- assertEquals(OMMonitor.TEN, monitor.getTotalWork());
- assertEquals(monitor.getTotalWork(), monitor.getWork());
- assertSimilar(OMMonitor.ONE, main.getWork(), 1000);
- }
-
- // Worked incompletely
- {
- OMMonitor main = new Monitor().begin();
- assertEquals(OMMonitor.ONE, main.getTotalWork());
-
- OMMonitor monitor = main.fork();
- assertNotSame(OMMonitor.ZERO, monitor.getTotalWork());
- assertEquals(OMMonitor.ZERO, monitor.getWork());
-
- monitor.begin(OMMonitor.TEN);
- assertEquals(OMMonitor.TEN, monitor.getTotalWork());
- assertEquals(OMMonitor.ZERO, monitor.getWork());
-
- for (int i = 0; i < 5; i++)
- {
- monitor.worked();
- assertEquals(OMMonitor.TEN, monitor.getTotalWork());
- assertEquals((double)i + 1, monitor.getWork());
- assertSimilar(OMMonitor.ONE / OMMonitor.TEN * (i + 1), main.getWork(), 1000);
- }
-
- monitor.done();
- assertEquals(OMMonitor.TEN, monitor.getTotalWork());
- assertEquals(monitor.getTotalWork(), monitor.getWork());
- assertSimilar(OMMonitor.ONE, main.getWork(), 1000);
- }
- }
-
- public void testAsyncProgress() throws Exception
- {
- final long PERIOD = 50;
- OMMonitor main = new Monitor()
- {
- @Override
- protected long getAsyncSchedulePeriod()
- {
- return PERIOD;
- }
- }.begin(3);
-
- main.worked();
- double work = main.getWork();
- assertEquals(OMMonitor.ONE, work);
-
- Async async = main.forkAsync();
- for (int i = 0; i < 20; i++)
- {
- sleep(2 * PERIOD);
- double newWork = main.getWork();
- System.out.println(newWork);
-
- // assertEquals(true, "Worked not enough: " + work, newWork > work);
- // assertEquals(true, "Worked too much: " + newWork, newWork < OMMonitor.ONE + OMMonitor.ONE);
- work = newWork;
- }
-
- async.stop();
- assertSimilar(OMMonitor.ONE + OMMonitor.ONE, main.getWork(), 1000);
-
- main.worked();
- assertSimilar(OMMonitor.ONE + OMMonitor.ONE + OMMonitor.ONE, main.getWork(), 1000);
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.util.tests;
+
+import org.eclipse.net4j.util.om.monitor.Monitor;
+import org.eclipse.net4j.util.om.monitor.OMMonitor;
+import org.eclipse.net4j.util.om.monitor.OMMonitor.Async;
+
+/**
+ * @author Eike Stepper
+ */
+public class MonitorTest extends AbstractOMTest
+{
+ public void testBeginNotCalledOnMonitor() throws Exception
+ {
+ try
+ {
+ OMMonitor monitor = new Monitor();
+ monitor.worked();
+ fail("IllegalStateException expected"); //$NON-NLS-1$
+ }
+ catch (IllegalStateException ex)
+ {
+ // Success
+ }
+
+ try
+ {
+ OMMonitor monitor = new Monitor();
+ monitor.fork();
+ fail("IllegalStateException expected"); //$NON-NLS-1$
+ }
+ catch (IllegalStateException ex)
+ {
+ // Success
+ }
+
+ Async async = null;
+ try
+ {
+ OMMonitor monitor = new Monitor();
+ async = monitor.forkAsync();
+ fail("IllegalStateException expected"); //$NON-NLS-1$
+ }
+ catch (IllegalStateException ex)
+ {
+ // Success
+ }
+ finally
+ {
+ if (async != null)
+ {
+ async.stop();
+ }
+ }
+ }
+
+ public void testBeginNotCalledOnNestedMonitor() throws Exception
+ {
+ try
+ {
+ OMMonitor monitor = new Monitor().begin().fork();
+ monitor.worked();
+ fail("IllegalStateException expected"); //$NON-NLS-1$
+ }
+ catch (IllegalStateException ex)
+ {
+ // Success
+ }
+
+ try
+ {
+ OMMonitor monitor = new Monitor().begin().fork();
+ monitor.fork();
+ fail("IllegalStateException expected"); //$NON-NLS-1$
+ }
+ catch (IllegalStateException ex)
+ {
+ // Success
+ }
+
+ Async async = null;
+ try
+ {
+ OMMonitor monitor = new Monitor().begin().fork();
+ async = monitor.forkAsync();
+ fail("IllegalStateException expected"); //$NON-NLS-1$
+ }
+ catch (IllegalStateException ex)
+ {
+ // Success
+ }
+ finally
+ {
+ if (async != null)
+ {
+ async.stop();
+ }
+ }
+ }
+
+ public void testBeginCalledOnMonitor() throws Exception
+ {
+ {
+ OMMonitor monitor = new Monitor().begin();
+ monitor.worked();
+ }
+
+ {
+ OMMonitor monitor = new Monitor().begin();
+ monitor.fork();
+ }
+
+ Async async = null;
+ try
+ {
+ OMMonitor monitor = new Monitor().begin();
+ async = monitor.forkAsync();
+ }
+ finally
+ {
+ if (async != null)
+ {
+ async.stop();
+ }
+ }
+ }
+
+ public void testBeginCalledOnNestedMonitor() throws Exception
+ {
+ {
+ OMMonitor monitor = new Monitor().begin().fork().begin();
+ monitor.worked();
+ }
+
+ {
+ OMMonitor monitor = new Monitor().begin().fork().begin();
+ monitor.fork();
+ }
+
+ Async async = null;
+ try
+ {
+ OMMonitor monitor = new Monitor().begin().fork().begin();
+ async = monitor.forkAsync();
+ }
+ finally
+ {
+ if (async != null)
+ {
+ async.stop();
+ }
+ }
+ }
+
+ public void testProgress() throws Exception
+ {
+ // Worked completely
+ {
+ OMMonitor monitor = new Monitor();
+ assertNotSame(OMMonitor.ZERO, monitor.getTotalWork());
+ assertEquals(OMMonitor.ZERO, monitor.getWork());
+
+ monitor.begin(OMMonitor.TEN);
+ assertEquals(OMMonitor.TEN, monitor.getTotalWork());
+ assertEquals(OMMonitor.ZERO, monitor.getWork());
+
+ for (int i = 0; i < 10; i++)
+ {
+ monitor.worked();
+ assertEquals(OMMonitor.TEN, monitor.getTotalWork());
+ assertEquals((double)i + 1, monitor.getWork());
+ }
+
+ monitor.done();
+ assertEquals(OMMonitor.TEN, monitor.getTotalWork());
+ assertEquals(monitor.getTotalWork(), monitor.getWork());
+ }
+
+ // Worked incompletely
+ {
+ OMMonitor monitor = new Monitor();
+ assertNotSame(OMMonitor.ZERO, monitor.getTotalWork());
+ assertEquals(OMMonitor.ZERO, monitor.getWork());
+
+ monitor.begin(OMMonitor.TEN);
+ assertEquals(OMMonitor.TEN, monitor.getTotalWork());
+ assertEquals(OMMonitor.ZERO, monitor.getWork());
+
+ for (int i = 0; i < 5; i++)
+ {
+ monitor.worked();
+ assertEquals(OMMonitor.TEN, monitor.getTotalWork());
+ assertEquals((double)i + 1, monitor.getWork());
+ }
+
+ monitor.done();
+ assertEquals(OMMonitor.TEN, monitor.getTotalWork());
+ assertEquals(monitor.getTotalWork(), monitor.getWork());
+ }
+ }
+
+ public void testNestedProgress() throws Exception
+ {
+ // Worked completely
+ {
+ OMMonitor main = new Monitor().begin();
+ assertEquals(OMMonitor.ONE, main.getTotalWork());
+
+ OMMonitor monitor = main.fork();
+ assertNotSame(OMMonitor.ZERO, monitor.getTotalWork());
+ assertEquals(OMMonitor.ZERO, monitor.getWork());
+
+ monitor.begin(OMMonitor.TEN);
+ assertEquals(OMMonitor.TEN, monitor.getTotalWork());
+ assertEquals(OMMonitor.ZERO, monitor.getWork());
+
+ for (int i = 0; i < 10; i++)
+ {
+ monitor.worked();
+ assertEquals(OMMonitor.TEN, monitor.getTotalWork());
+ assertEquals((double)i + 1, monitor.getWork());
+ assertSimilar(OMMonitor.ONE / OMMonitor.TEN * (i + 1), main.getWork(), 1000);
+ }
+
+ monitor.done();
+ assertEquals(OMMonitor.TEN, monitor.getTotalWork());
+ assertEquals(monitor.getTotalWork(), monitor.getWork());
+ assertSimilar(OMMonitor.ONE, main.getWork(), 1000);
+ }
+
+ // Worked incompletely
+ {
+ OMMonitor main = new Monitor().begin();
+ assertEquals(OMMonitor.ONE, main.getTotalWork());
+
+ OMMonitor monitor = main.fork();
+ assertNotSame(OMMonitor.ZERO, monitor.getTotalWork());
+ assertEquals(OMMonitor.ZERO, monitor.getWork());
+
+ monitor.begin(OMMonitor.TEN);
+ assertEquals(OMMonitor.TEN, monitor.getTotalWork());
+ assertEquals(OMMonitor.ZERO, monitor.getWork());
+
+ for (int i = 0; i < 5; i++)
+ {
+ monitor.worked();
+ assertEquals(OMMonitor.TEN, monitor.getTotalWork());
+ assertEquals((double)i + 1, monitor.getWork());
+ assertSimilar(OMMonitor.ONE / OMMonitor.TEN * (i + 1), main.getWork(), 1000);
+ }
+
+ monitor.done();
+ assertEquals(OMMonitor.TEN, monitor.getTotalWork());
+ assertEquals(monitor.getTotalWork(), monitor.getWork());
+ assertSimilar(OMMonitor.ONE, main.getWork(), 1000);
+ }
+ }
+
+ public void testAsyncProgress() throws Exception
+ {
+ final long PERIOD = 50;
+ OMMonitor main = new Monitor()
+ {
+ @Override
+ protected long getAsyncSchedulePeriod()
+ {
+ return PERIOD;
+ }
+ }.begin(3);
+
+ main.worked();
+ double work = main.getWork();
+ assertEquals(OMMonitor.ONE, work);
+
+ Async async = main.forkAsync();
+ for (int i = 0; i < 20; i++)
+ {
+ sleep(2 * PERIOD);
+ double newWork = main.getWork();
+ System.out.println(newWork);
+
+ // assertEquals(true, "Worked not enough: " + work, newWork > work);
+ // assertEquals(true, "Worked too much: " + newWork, newWork < OMMonitor.ONE + OMMonitor.ONE);
+ work = newWork;
+ }
+
+ async.stop();
+ assertSimilar(OMMonitor.ONE + OMMonitor.ONE, main.getWork(), 1000);
+
+ main.worked();
+ assertSimilar(OMMonitor.ONE + OMMonitor.ONE + OMMonitor.ONE, main.getWork(), 1000);
+ }
+}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/MultiMapTest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/MultiMapTest.java
index d7493f6ded..8eddb83df0 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/MultiMapTest.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/MultiMapTest.java
@@ -1,291 +1,291 @@
-/*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- */
-package org.eclipse.net4j.util.tests;
-
-import org.eclipse.net4j.util.collection.MapEntry;
-import org.eclipse.net4j.util.collection.MultiMap.ListBased;
-
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-/**
- * @author Eike Stepper
- */
-public class MultiMapTest extends AbstractOMTest
-{
- public void testListBased() throws Exception
- {
- ListBased<Integer, String> multiMap = new ListBased<Integer, String>();
- assertEquals(true, multiMap.isEmpty());
- assertEquals(0, multiMap.size());
- assertEquals(false, multiMap.containsKey(1));
- assertEquals(false, multiMap.containsValue("value" + 1)); //$NON-NLS-1$
- assertEquals(null, multiMap.get(1));
-
- addDelegate(multiMap, 0, 0);
- assertEquals(true, multiMap.isEmpty());
- assertEquals(0, multiMap.size());
- assertEquals(false, multiMap.containsKey(1));
- assertEquals(false, multiMap.containsValue("value" + 1)); //$NON-NLS-1$
- assertEquals(null, multiMap.get(1));
-
- addDelegate(multiMap, 1, 10);
- addDelegate(multiMap, 11, 10);
- addDelegate(multiMap, 21, 10);
- assertEquals(false, multiMap.isEmpty());
- assertEquals(30, multiMap.size());
- assertEquals(true, multiMap.containsKey(1));
- assertEquals(true, multiMap.containsValue("value" + 1)); //$NON-NLS-1$
- assertEquals("value" + 1, multiMap.get(1)); //$NON-NLS-1$
- assertEquals("value" + 6, multiMap.get(6)); //$NON-NLS-1$
-
- addDelegate(multiMap, 6, 10);
- assertEquals(false, multiMap.isEmpty());
- assertEquals(30, multiMap.size());
- assertEquals(true, multiMap.containsKey(1));
- assertEquals(true, multiMap.containsValue("value" + 1)); //$NON-NLS-1$
- assertEquals("value" + 1, multiMap.get(1)); //$NON-NLS-1$
- assertEquals("value" + 6, multiMap.get(6)); //$NON-NLS-1$
- assertEquals(null, multiMap.get(35));
-
- addDelegate(multiMap, 26, 10);
- assertEquals(false, multiMap.isEmpty());
- assertEquals(35, multiMap.size());
- assertEquals(true, multiMap.containsKey(1));
- assertEquals(true, multiMap.containsValue("value" + 1)); //$NON-NLS-1$
- assertEquals("value" + 1, multiMap.get(1)); //$NON-NLS-1$
- assertEquals("value" + 6, multiMap.get(6)); //$NON-NLS-1$
- assertEquals("value" + 35, multiMap.get(35)); //$NON-NLS-1$
- }
-
- public void testEntrySet() throws Exception
- {
- ListBased<Integer, String> multiMap = new ListBased<Integer, String>();
- assertEquals(true, multiMap.entrySet().isEmpty());
- assertEquals(0, multiMap.entrySet().size());
- assertEquals(false, multiMap.entrySet().contains(new MapEntry<Integer, String>(1, "value1"))); //$NON-NLS-1$
-
- addDelegate(multiMap, 0, 0);
- assertEquals(true, multiMap.entrySet().isEmpty());
- assertEquals(0, multiMap.entrySet().size());
- assertEquals(false, multiMap.entrySet().contains(new MapEntry<Integer, String>(1, "value1"))); //$NON-NLS-1$
-
- addDelegate(multiMap, 1, 10);
- addDelegate(multiMap, 11, 10);
- addDelegate(multiMap, 21, 10);
- assertEquals(false, multiMap.entrySet().isEmpty());
- assertEquals(30, multiMap.entrySet().size());
- assertEquals(true, multiMap.entrySet().contains(new MapEntry<Integer, String>(1, "value1"))); //$NON-NLS-1$
-
- addDelegate(multiMap, 6, 10);
- assertEquals(false, multiMap.entrySet().isEmpty());
- assertEquals(30, multiMap.entrySet().size());
- assertEquals(true, multiMap.entrySet().contains(new MapEntry<Integer, String>(1, "value1"))); //$NON-NLS-1$
- assertEquals(false, multiMap.entrySet().contains(new MapEntry<Integer, String>(35, "value35"))); //$NON-NLS-1$
-
- addDelegate(multiMap, 26, 10);
- assertEquals(false, multiMap.entrySet().isEmpty());
- assertEquals(35, multiMap.entrySet().size());
- assertEquals(true, multiMap.entrySet().contains(new MapEntry<Integer, String>(1, "value1"))); //$NON-NLS-1$
- assertEquals(true, multiMap.entrySet().contains(new MapEntry<Integer, String>(35, "value35"))); //$NON-NLS-1$
- }
-
- public void testKeySet() throws Exception
- {
- ListBased<Integer, String> multiMap = new ListBased<Integer, String>();
- assertEquals(true, multiMap.keySet().isEmpty());
- assertEquals(0, multiMap.keySet().size());
- assertEquals(false, multiMap.keySet().contains(1));
-
- addDelegate(multiMap, 0, 0);
- assertEquals(true, multiMap.keySet().isEmpty());
- assertEquals(0, multiMap.keySet().size());
- assertEquals(false, multiMap.keySet().contains(1));
-
- addDelegate(multiMap, 1, 10);
- addDelegate(multiMap, 11, 10);
- addDelegate(multiMap, 21, 10);
- assertEquals(false, multiMap.keySet().isEmpty());
- assertEquals(30, multiMap.keySet().size());
- assertEquals(true, multiMap.keySet().contains(1));
-
- addDelegate(multiMap, 6, 10);
- assertEquals(false, multiMap.keySet().isEmpty());
- assertEquals(30, multiMap.keySet().size());
- assertEquals(true, multiMap.keySet().contains(1));
- assertEquals(false, multiMap.keySet().contains(35));
-
- addDelegate(multiMap, 26, 10);
- assertEquals(false, multiMap.keySet().isEmpty());
- assertEquals(35, multiMap.keySet().size());
- assertEquals(true, multiMap.keySet().contains(1));
- assertEquals(true, multiMap.keySet().contains(35));
- }
-
- public void testValues() throws Exception
- {
- ListBased<Integer, String> multiMap = new ListBased<Integer, String>();
- assertEquals(true, multiMap.values().isEmpty());
- assertEquals(0, multiMap.values().size());
- assertEquals(false, multiMap.values().contains("value1")); //$NON-NLS-1$
-
- addDelegate(multiMap, 0, 0);
- assertEquals(true, multiMap.values().isEmpty());
- assertEquals(0, multiMap.values().size());
- assertEquals(false, multiMap.values().contains("value1")); //$NON-NLS-1$
-
- addDelegate(multiMap, 1, 10);
- addDelegate(multiMap, 11, 10);
- addDelegate(multiMap, 21, 10);
- assertEquals(false, multiMap.values().isEmpty());
- assertEquals(30, multiMap.values().size());
- assertEquals(true, multiMap.values().contains("value1")); //$NON-NLS-1$
-
- addDelegate(multiMap, 6, 10);
- assertEquals(false, multiMap.values().isEmpty());
- assertEquals(30, multiMap.values().size());
- assertEquals(true, multiMap.values().contains("value1")); //$NON-NLS-1$
- assertEquals(false, multiMap.values().contains("value35")); //$NON-NLS-1$
-
- addDelegate(multiMap, 26, 10);
- assertEquals(false, multiMap.values().isEmpty());
- assertEquals(35, multiMap.values().size());
- assertEquals(true, multiMap.values().contains("value1")); //$NON-NLS-1$
- assertEquals(true, multiMap.values().contains("value35")); //$NON-NLS-1$
- }
-
- public void testEntrySetIterator() throws Exception
- {
- ListBased<Integer, String> multiMap = new ListBased<Integer, String>();
- assertIterator(new HashSet<Object>(), multiMap.entrySet());
-
- addDelegate(multiMap, 0, 0);
- assertIterator(new HashSet<Object>(), multiMap.entrySet());
-
- addDelegate(multiMap, 1, 10);
- addDelegate(multiMap, 11, 10);
- addDelegate(multiMap, 21, 10);
- assertIterator(createMapEntries(1, 30), multiMap.entrySet());
-
- addDelegate(multiMap, 6, 10);
- assertIterator(createMapEntries(1, 30), multiMap.entrySet());
-
- addDelegate(multiMap, 26, 10);
- assertIterator(createMapEntries(1, 35), multiMap.entrySet());
- }
-
- public void testKeySetIterator() throws Exception
- {
- ListBased<Integer, String> multiMap = new ListBased<Integer, String>();
- assertIterator(new HashSet<Object>(), multiMap.keySet());
-
- addDelegate(multiMap, 0, 0);
- assertIterator(new HashSet<Object>(), multiMap.keySet());
-
- addDelegate(multiMap, 1, 10);
- addDelegate(multiMap, 11, 10);
- addDelegate(multiMap, 21, 10);
- assertIterator(createKeys(1, 30), multiMap.keySet());
-
- addDelegate(multiMap, 6, 10);
- assertIterator(createKeys(1, 30), multiMap.keySet());
-
- addDelegate(multiMap, 26, 10);
- assertIterator(createKeys(1, 35), multiMap.keySet());
- }
-
- public void testValuesIterator() throws Exception
- {
- ListBased<Integer, String> multiMap = new ListBased<Integer, String>();
- assertIterator(new HashSet<Object>(), multiMap.values());
-
- addDelegate(multiMap, 0, 0);
- assertIterator(new HashSet<Object>(), multiMap.values());
-
- addDelegate(multiMap, 1, 10);
- addDelegate(multiMap, 11, 10);
- addDelegate(multiMap, 21, 10);
- assertIterator(createValues(1, 30), multiMap.values());
-
- addDelegate(multiMap, 6, 10);
- assertIterator(createValues(1, 30), multiMap.values());
-
- addDelegate(multiMap, 26, 10);
- assertIterator(createValues(1, 35), multiMap.values());
- }
-
- private void addDelegate(ListBased<Integer, String> multiMap, int start, int count)
- {
- Map<Integer, String> map = new HashMap<Integer, String>();
- for (int i = 0; i < count; i++)
- {
- int key = start + i;
- map.put(key, "value" + key); //$NON-NLS-1$
- }
-
- multiMap.getDelegates().add(map);
- }
-
- private void assertIterator(Set<?> expectedObjects, Collection<?> actualObjects)
- {
- for (Object actualObject : actualObjects)
- {
- if (!expectedObjects.remove(actualObject))
- {
- fail("Unexpected object: " + actualObject); //$NON-NLS-1$
- }
- }
-
- if (!expectedObjects.isEmpty())
- {
- fail("Missing objects: " + expectedObjects); //$NON-NLS-1$
- }
- }
-
- private Set<Object> createMapEntries(int start, int count)
- {
- Set<Object> result = new HashSet<Object>();
- for (int i = 0; i < count; i++)
- {
- int key = start + i;
- result.add(new MapEntry<Integer, String>(key, "value" + key)); //$NON-NLS-1$
- }
-
- return result;
- }
-
- private Set<Object> createKeys(int start, int count)
- {
- Set<Object> result = new HashSet<Object>();
- for (int i = 0; i < count; i++)
- {
- int key = start + i;
- result.add(key);
- }
-
- return result;
- }
-
- private Set<Object> createValues(int start, int count)
- {
- Set<Object> result = new HashSet<Object>();
- for (int i = 0; i < count; i++)
- {
- int key = start + i;
- result.add("value" + key); //$NON-NLS-1$
- }
-
- return result;
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.util.tests;
+
+import org.eclipse.net4j.util.collection.MapEntry;
+import org.eclipse.net4j.util.collection.MultiMap.ListBased;
+
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * @author Eike Stepper
+ */
+public class MultiMapTest extends AbstractOMTest
+{
+ public void testListBased() throws Exception
+ {
+ ListBased<Integer, String> multiMap = new ListBased<Integer, String>();
+ assertEquals(true, multiMap.isEmpty());
+ assertEquals(0, multiMap.size());
+ assertEquals(false, multiMap.containsKey(1));
+ assertEquals(false, multiMap.containsValue("value" + 1)); //$NON-NLS-1$
+ assertEquals(null, multiMap.get(1));
+
+ addDelegate(multiMap, 0, 0);
+ assertEquals(true, multiMap.isEmpty());
+ assertEquals(0, multiMap.size());
+ assertEquals(false, multiMap.containsKey(1));
+ assertEquals(false, multiMap.containsValue("value" + 1)); //$NON-NLS-1$
+ assertEquals(null, multiMap.get(1));
+
+ addDelegate(multiMap, 1, 10);
+ addDelegate(multiMap, 11, 10);
+ addDelegate(multiMap, 21, 10);
+ assertEquals(false, multiMap.isEmpty());
+ assertEquals(30, multiMap.size());
+ assertEquals(true, multiMap.containsKey(1));
+ assertEquals(true, multiMap.containsValue("value" + 1)); //$NON-NLS-1$
+ assertEquals("value" + 1, multiMap.get(1)); //$NON-NLS-1$
+ assertEquals("value" + 6, multiMap.get(6)); //$NON-NLS-1$
+
+ addDelegate(multiMap, 6, 10);
+ assertEquals(false, multiMap.isEmpty());
+ assertEquals(30, multiMap.size());
+ assertEquals(true, multiMap.containsKey(1));
+ assertEquals(true, multiMap.containsValue("value" + 1)); //$NON-NLS-1$
+ assertEquals("value" + 1, multiMap.get(1)); //$NON-NLS-1$
+ assertEquals("value" + 6, multiMap.get(6)); //$NON-NLS-1$
+ assertEquals(null, multiMap.get(35));
+
+ addDelegate(multiMap, 26, 10);
+ assertEquals(false, multiMap.isEmpty());
+ assertEquals(35, multiMap.size());
+ assertEquals(true, multiMap.containsKey(1));
+ assertEquals(true, multiMap.containsValue("value" + 1)); //$NON-NLS-1$
+ assertEquals("value" + 1, multiMap.get(1)); //$NON-NLS-1$
+ assertEquals("value" + 6, multiMap.get(6)); //$NON-NLS-1$
+ assertEquals("value" + 35, multiMap.get(35)); //$NON-NLS-1$
+ }
+
+ public void testEntrySet() throws Exception
+ {
+ ListBased<Integer, String> multiMap = new ListBased<Integer, String>();
+ assertEquals(true, multiMap.entrySet().isEmpty());
+ assertEquals(0, multiMap.entrySet().size());
+ assertEquals(false, multiMap.entrySet().contains(new MapEntry<Integer, String>(1, "value1"))); //$NON-NLS-1$
+
+ addDelegate(multiMap, 0, 0);
+ assertEquals(true, multiMap.entrySet().isEmpty());
+ assertEquals(0, multiMap.entrySet().size());
+ assertEquals(false, multiMap.entrySet().contains(new MapEntry<Integer, String>(1, "value1"))); //$NON-NLS-1$
+
+ addDelegate(multiMap, 1, 10);
+ addDelegate(multiMap, 11, 10);
+ addDelegate(multiMap, 21, 10);
+ assertEquals(false, multiMap.entrySet().isEmpty());
+ assertEquals(30, multiMap.entrySet().size());
+ assertEquals(true, multiMap.entrySet().contains(new MapEntry<Integer, String>(1, "value1"))); //$NON-NLS-1$
+
+ addDelegate(multiMap, 6, 10);
+ assertEquals(false, multiMap.entrySet().isEmpty());
+ assertEquals(30, multiMap.entrySet().size());
+ assertEquals(true, multiMap.entrySet().contains(new MapEntry<Integer, String>(1, "value1"))); //$NON-NLS-1$
+ assertEquals(false, multiMap.entrySet().contains(new MapEntry<Integer, String>(35, "value35"))); //$NON-NLS-1$
+
+ addDelegate(multiMap, 26, 10);
+ assertEquals(false, multiMap.entrySet().isEmpty());
+ assertEquals(35, multiMap.entrySet().size());
+ assertEquals(true, multiMap.entrySet().contains(new MapEntry<Integer, String>(1, "value1"))); //$NON-NLS-1$
+ assertEquals(true, multiMap.entrySet().contains(new MapEntry<Integer, String>(35, "value35"))); //$NON-NLS-1$
+ }
+
+ public void testKeySet() throws Exception
+ {
+ ListBased<Integer, String> multiMap = new ListBased<Integer, String>();
+ assertEquals(true, multiMap.keySet().isEmpty());
+ assertEquals(0, multiMap.keySet().size());
+ assertEquals(false, multiMap.keySet().contains(1));
+
+ addDelegate(multiMap, 0, 0);
+ assertEquals(true, multiMap.keySet().isEmpty());
+ assertEquals(0, multiMap.keySet().size());
+ assertEquals(false, multiMap.keySet().contains(1));
+
+ addDelegate(multiMap, 1, 10);
+ addDelegate(multiMap, 11, 10);
+ addDelegate(multiMap, 21, 10);
+ assertEquals(false, multiMap.keySet().isEmpty());
+ assertEquals(30, multiMap.keySet().size());
+ assertEquals(true, multiMap.keySet().contains(1));
+
+ addDelegate(multiMap, 6, 10);
+ assertEquals(false, multiMap.keySet().isEmpty());
+ assertEquals(30, multiMap.keySet().size());
+ assertEquals(true, multiMap.keySet().contains(1));
+ assertEquals(false, multiMap.keySet().contains(35));
+
+ addDelegate(multiMap, 26, 10);
+ assertEquals(false, multiMap.keySet().isEmpty());
+ assertEquals(35, multiMap.keySet().size());
+ assertEquals(true, multiMap.keySet().contains(1));
+ assertEquals(true, multiMap.keySet().contains(35));
+ }
+
+ public void testValues() throws Exception
+ {
+ ListBased<Integer, String> multiMap = new ListBased<Integer, String>();
+ assertEquals(true, multiMap.values().isEmpty());
+ assertEquals(0, multiMap.values().size());
+ assertEquals(false, multiMap.values().contains("value1")); //$NON-NLS-1$
+
+ addDelegate(multiMap, 0, 0);
+ assertEquals(true, multiMap.values().isEmpty());
+ assertEquals(0, multiMap.values().size());
+ assertEquals(false, multiMap.values().contains("value1")); //$NON-NLS-1$
+
+ addDelegate(multiMap, 1, 10);
+ addDelegate(multiMap, 11, 10);
+ addDelegate(multiMap, 21, 10);
+ assertEquals(false, multiMap.values().isEmpty());
+ assertEquals(30, multiMap.values().size());
+ assertEquals(true, multiMap.values().contains("value1")); //$NON-NLS-1$
+
+ addDelegate(multiMap, 6, 10);
+ assertEquals(false, multiMap.values().isEmpty());
+ assertEquals(30, multiMap.values().size());
+ assertEquals(true, multiMap.values().contains("value1")); //$NON-NLS-1$
+ assertEquals(false, multiMap.values().contains("value35")); //$NON-NLS-1$
+
+ addDelegate(multiMap, 26, 10);
+ assertEquals(false, multiMap.values().isEmpty());
+ assertEquals(35, multiMap.values().size());
+ assertEquals(true, multiMap.values().contains("value1")); //$NON-NLS-1$
+ assertEquals(true, multiMap.values().contains("value35")); //$NON-NLS-1$
+ }
+
+ public void testEntrySetIterator() throws Exception
+ {
+ ListBased<Integer, String> multiMap = new ListBased<Integer, String>();
+ assertIterator(new HashSet<Object>(), multiMap.entrySet());
+
+ addDelegate(multiMap, 0, 0);
+ assertIterator(new HashSet<Object>(), multiMap.entrySet());
+
+ addDelegate(multiMap, 1, 10);
+ addDelegate(multiMap, 11, 10);
+ addDelegate(multiMap, 21, 10);
+ assertIterator(createMapEntries(1, 30), multiMap.entrySet());
+
+ addDelegate(multiMap, 6, 10);
+ assertIterator(createMapEntries(1, 30), multiMap.entrySet());
+
+ addDelegate(multiMap, 26, 10);
+ assertIterator(createMapEntries(1, 35), multiMap.entrySet());
+ }
+
+ public void testKeySetIterator() throws Exception
+ {
+ ListBased<Integer, String> multiMap = new ListBased<Integer, String>();
+ assertIterator(new HashSet<Object>(), multiMap.keySet());
+
+ addDelegate(multiMap, 0, 0);
+ assertIterator(new HashSet<Object>(), multiMap.keySet());
+
+ addDelegate(multiMap, 1, 10);
+ addDelegate(multiMap, 11, 10);
+ addDelegate(multiMap, 21, 10);
+ assertIterator(createKeys(1, 30), multiMap.keySet());
+
+ addDelegate(multiMap, 6, 10);
+ assertIterator(createKeys(1, 30), multiMap.keySet());
+
+ addDelegate(multiMap, 26, 10);
+ assertIterator(createKeys(1, 35), multiMap.keySet());
+ }
+
+ public void testValuesIterator() throws Exception
+ {
+ ListBased<Integer, String> multiMap = new ListBased<Integer, String>();
+ assertIterator(new HashSet<Object>(), multiMap.values());
+
+ addDelegate(multiMap, 0, 0);
+ assertIterator(new HashSet<Object>(), multiMap.values());
+
+ addDelegate(multiMap, 1, 10);
+ addDelegate(multiMap, 11, 10);
+ addDelegate(multiMap, 21, 10);
+ assertIterator(createValues(1, 30), multiMap.values());
+
+ addDelegate(multiMap, 6, 10);
+ assertIterator(createValues(1, 30), multiMap.values());
+
+ addDelegate(multiMap, 26, 10);
+ assertIterator(createValues(1, 35), multiMap.values());
+ }
+
+ private void addDelegate(ListBased<Integer, String> multiMap, int start, int count)
+ {
+ Map<Integer, String> map = new HashMap<Integer, String>();
+ for (int i = 0; i < count; i++)
+ {
+ int key = start + i;
+ map.put(key, "value" + key); //$NON-NLS-1$
+ }
+
+ multiMap.getDelegates().add(map);
+ }
+
+ private void assertIterator(Set<?> expectedObjects, Collection<?> actualObjects)
+ {
+ for (Object actualObject : actualObjects)
+ {
+ if (!expectedObjects.remove(actualObject))
+ {
+ fail("Unexpected object: " + actualObject); //$NON-NLS-1$
+ }
+ }
+
+ if (!expectedObjects.isEmpty())
+ {
+ fail("Missing objects: " + expectedObjects); //$NON-NLS-1$
+ }
+ }
+
+ private Set<Object> createMapEntries(int start, int count)
+ {
+ Set<Object> result = new HashSet<Object>();
+ for (int i = 0; i < count; i++)
+ {
+ int key = start + i;
+ result.add(new MapEntry<Integer, String>(key, "value" + key)); //$NON-NLS-1$
+ }
+
+ return result;
+ }
+
+ private Set<Object> createKeys(int start, int count)
+ {
+ Set<Object> result = new HashSet<Object>();
+ for (int i = 0; i < count; i++)
+ {
+ int key = start + i;
+ result.add(key);
+ }
+
+ return result;
+ }
+
+ private Set<Object> createValues(int start, int count)
+ {
+ Set<Object> result = new HashSet<Object>();
+ for (int i = 0; i < count; i++)
+ {
+ int key = start + i;
+ result.add("value" + key); //$NON-NLS-1$
+ }
+
+ return result;
+ }
+}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/OMTest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/OMTest.java
index 169796bf9e..03659e4bb6 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/OMTest.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/OMTest.java
@@ -1,47 +1,47 @@
-/*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- */
-package org.eclipse.net4j.util.tests;
-
-import org.eclipse.net4j.util.io.IOUtil;
-import org.eclipse.net4j.util.om.OMBundle;
-
-import java.io.InputStream;
-import java.net.URL;
-
-/**
- * @author Eike Stepper
- */
-public class OMTest
-{
- /**
- * Requires this class to be exported to a jar file in this project's plugins/ folder!<br>
- * Also requires an export of the net4j.util bundle in the same folder!
- */
- public static void main(String[] args) throws Exception
- {
- OMBundle bundle = org.eclipse.net4j.internal.util.bundle.OM.BUNDLE;
-
- URL baseUrl = bundle.getBaseURL();
- IOUtil.OUT().println(baseUrl);
- IOUtil.OUT().println();
-
- InputStream stream = bundle.getInputStream("/plugin.xml"); //$NON-NLS-1$
-
- try
- {
- IOUtil.copy(stream, IOUtil.OUT());
- }
- finally
- {
- IOUtil.close(stream);
- }
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.util.tests;
+
+import org.eclipse.net4j.util.io.IOUtil;
+import org.eclipse.net4j.util.om.OMBundle;
+
+import java.io.InputStream;
+import java.net.URL;
+
+/**
+ * @author Eike Stepper
+ */
+public class OMTest
+{
+ /**
+ * Requires this class to be exported to a jar file in this project's plugins/ folder!<br>
+ * Also requires an export of the net4j.util bundle in the same folder!
+ */
+ public static void main(String[] args) throws Exception
+ {
+ OMBundle bundle = org.eclipse.net4j.internal.util.bundle.OM.BUNDLE;
+
+ URL baseUrl = bundle.getBaseURL();
+ IOUtil.OUT().println(baseUrl);
+ IOUtil.OUT().println();
+
+ InputStream stream = bundle.getInputStream("/plugin.xml"); //$NON-NLS-1$
+
+ try
+ {
+ IOUtil.copy(stream, IOUtil.OUT());
+ }
+ finally
+ {
+ IOUtil.close(stream);
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/QueueWorkerWorkSerializerTest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/QueueWorkerWorkSerializerTest.java
index 78066db828..eaead2bd36 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/QueueWorkerWorkSerializerTest.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/QueueWorkerWorkSerializerTest.java
@@ -1,216 +1,216 @@
-/*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Andre Dietisheim - initial API and implementation
- * Eike Stepper - maintenance
- */
-package org.eclipse.net4j.util.tests;
-
-import org.eclipse.net4j.util.concurrent.QueueWorkerWorkSerializer;
-import org.eclipse.net4j.util.io.IOUtil;
-
-import java.util.Random;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicInteger;
-
-/**
- * A test for {@link QueueWorkerWorkSerializer}.
- *
- * @author Andre Dietisheim
- */
-public class QueueWorkerWorkSerializerTest extends AbstractOMTest
-{
- /** timeout to wait for execution of all work units. */
- private static final int WORK_COMPLETION_TIMEOUT = 10000;
-
- /** number of work producer threads. */
- private static final int NUM_WORKPRODUCER_THREADS = 10;
-
- /** number of working units to execute. */
- private static final int NUM_WORK = 40;
-
- /** the latch to wait on for the execution of all working units. */
- private CountDownLatch workConsumedLatch;
-
- /** The number of working units created. */
- private AtomicInteger workProduced;
-
- /** The thread pool to execute the work unit producers in. */
- private ExecutorService threadPool;
-
- /** The queue worker to submit the work units to. */
- private QueueWorkerWorkSerializer queueWorker;
-
- public QueueWorkerWorkSerializerTest()
- {
- }
-
- /**
- * Test that asserts that all submitted workers are executed
- */
- public void testAllWorkSubmittedIsConsumed() throws Throwable
- {
- createWorkProducerThreads(new WorkProducerFactory()
- {
- public WorkProducer createWorkProducer()
- {
- return new WorkProducer()
- {
- @Override
- protected Runnable createWork(int id)
- {
- return new Work(id);
- }
- };
- }
- });
-
- waitForAllWorkExecuted();
- assertEquals(workProduced.get(), NUM_WORK - workConsumedLatch.getCount());
- }
-
- /**
- * If the workers throw Exceptions, the QueueWorker stops executing work (deactivates its working thread). Therefore
- * the first work unit gets consumed, the rest is not executed any more.
- */
- public void testGivenWorkExceptionInWorkAllWorkSubmittedOnlyTheFirstWorkerIsConsumed() throws Throwable
- {
- createWorkProducerThreads(new WorkProducerFactory()
- {
- public WorkProducer createWorkProducer()
- {
- return new WorkProducer()
- {
- @Override
- protected Runnable createWork(int id)
- {
- return new Work(id)
- {
- @Override
- public void run()
- {
- super.run();
- throw new RuntimeException("dummy exception to simulate an error in executed workers");
- }
- };
- }
- };
- }
- });
-
- waitForAllWorkExecuted();
- assertEquals(NUM_WORK, workProduced.get());
- assertEquals(1, NUM_WORK - workConsumedLatch.getCount());
- }
-
- private void waitForAllWorkExecuted() throws InterruptedException
- {
- if (!workConsumedLatch.await(WORK_COMPLETION_TIMEOUT, TimeUnit.MILLISECONDS))
- {
- IOUtil.OUT().println("timeout occured before all workers were executed");
- }
- }
-
- private void createWorkProducerThreads(WorkProducerFactory factory)
- {
- for (int i = 0; i < NUM_WORKPRODUCER_THREADS; i++)
- {
- threadPool.submit(factory.createWorkProducer());
- }
- }
-
- /**
- * A factory that creates work units.
- */
- private static interface WorkProducerFactory
- {
- public WorkProducer createWorkProducer();
- }
-
- /**
- * A Runnable that creates work units
- */
- private abstract class WorkProducer implements Runnable
- {
- private Random random = new Random();
-
- /**
- * Produce work: add work units to the queue worker
- */
- public void run()
- {
- try
- {
- int currentWorkProduced;
- while ((currentWorkProduced = workProduced.getAndIncrement()) < NUM_WORK)
- {
- queueWorker.addWork(createWork(currentWorkProduced));
- Thread.sleep(random.nextInt(1000));
- }
-
- // correct last increment
- workProduced.decrementAndGet();
- IOUtil.OUT().println("work producer " + this + " stopped its production");
- }
- catch (InterruptedException ex)
- {
- return;
- }
- }
-
- /**
- * Creates a working unit (runnable).
- *
- * @param id
- * the id
- * @return the runnable
- */
- protected abstract Runnable createWork(int id);
- }
-
- /**
- * A simple work unit to be executed in the queueWorker.
- *
- * @author Andre Dietisheim
- */
- class Work implements Runnable
- {
- private final int id;
-
- private Work(int id)
- {
- this.id = id;
- IOUtil.OUT().println("work unit " + id + " created");
- }
-
- public void run()
- {
- workConsumedLatch.countDown();
- IOUtil.OUT().println("work unit " + id + " consumed");
- }
- }
-
- @Override
- public void setUp()
- {
- threadPool = Executors.newFixedThreadPool(NUM_WORKPRODUCER_THREADS);
- workConsumedLatch = new CountDownLatch(NUM_WORK);
- queueWorker = new QueueWorkerWorkSerializer();
- workProduced = new AtomicInteger(0);
- }
-
- @Override
- public void tearDown()
- {
- threadPool.shutdown();
- queueWorker.dispose();
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Andre Dietisheim - initial API and implementation
+ * Eike Stepper - maintenance
+ */
+package org.eclipse.net4j.util.tests;
+
+import org.eclipse.net4j.util.concurrent.QueueWorkerWorkSerializer;
+import org.eclipse.net4j.util.io.IOUtil;
+
+import java.util.Random;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * A test for {@link QueueWorkerWorkSerializer}.
+ *
+ * @author Andre Dietisheim
+ */
+public class QueueWorkerWorkSerializerTest extends AbstractOMTest
+{
+ /** timeout to wait for execution of all work units. */
+ private static final int WORK_COMPLETION_TIMEOUT = 10000;
+
+ /** number of work producer threads. */
+ private static final int NUM_WORKPRODUCER_THREADS = 10;
+
+ /** number of working units to execute. */
+ private static final int NUM_WORK = 40;
+
+ /** the latch to wait on for the execution of all working units. */
+ private CountDownLatch workConsumedLatch;
+
+ /** The number of working units created. */
+ private AtomicInteger workProduced;
+
+ /** The thread pool to execute the work unit producers in. */
+ private ExecutorService threadPool;
+
+ /** The queue worker to submit the work units to. */
+ private QueueWorkerWorkSerializer queueWorker;
+
+ public QueueWorkerWorkSerializerTest()
+ {
+ }
+
+ /**
+ * Test that asserts that all submitted workers are executed
+ */
+ public void testAllWorkSubmittedIsConsumed() throws Throwable
+ {
+ createWorkProducerThreads(new WorkProducerFactory()
+ {
+ public WorkProducer createWorkProducer()
+ {
+ return new WorkProducer()
+ {
+ @Override
+ protected Runnable createWork(int id)
+ {
+ return new Work(id);
+ }
+ };
+ }
+ });
+
+ waitForAllWorkExecuted();
+ assertEquals(workProduced.get(), NUM_WORK - workConsumedLatch.getCount());
+ }
+
+ /**
+ * If the workers throw Exceptions, the QueueWorker stops executing work (deactivates its working thread). Therefore
+ * the first work unit gets consumed, the rest is not executed any more.
+ */
+ public void testGivenWorkExceptionInWorkAllWorkSubmittedOnlyTheFirstWorkerIsConsumed() throws Throwable
+ {
+ createWorkProducerThreads(new WorkProducerFactory()
+ {
+ public WorkProducer createWorkProducer()
+ {
+ return new WorkProducer()
+ {
+ @Override
+ protected Runnable createWork(int id)
+ {
+ return new Work(id)
+ {
+ @Override
+ public void run()
+ {
+ super.run();
+ throw new RuntimeException("dummy exception to simulate an error in executed workers");
+ }
+ };
+ }
+ };
+ }
+ });
+
+ waitForAllWorkExecuted();
+ assertEquals(NUM_WORK, workProduced.get());
+ assertEquals(1, NUM_WORK - workConsumedLatch.getCount());
+ }
+
+ private void waitForAllWorkExecuted() throws InterruptedException
+ {
+ if (!workConsumedLatch.await(WORK_COMPLETION_TIMEOUT, TimeUnit.MILLISECONDS))
+ {
+ IOUtil.OUT().println("timeout occured before all workers were executed");
+ }
+ }
+
+ private void createWorkProducerThreads(WorkProducerFactory factory)
+ {
+ for (int i = 0; i < NUM_WORKPRODUCER_THREADS; i++)
+ {
+ threadPool.submit(factory.createWorkProducer());
+ }
+ }
+
+ /**
+ * A factory that creates work units.
+ */
+ private static interface WorkProducerFactory
+ {
+ public WorkProducer createWorkProducer();
+ }
+
+ /**
+ * A Runnable that creates work units
+ */
+ private abstract class WorkProducer implements Runnable
+ {
+ private Random random = new Random();
+
+ /**
+ * Produce work: add work units to the queue worker
+ */
+ public void run()
+ {
+ try
+ {
+ int currentWorkProduced;
+ while ((currentWorkProduced = workProduced.getAndIncrement()) < NUM_WORK)
+ {
+ queueWorker.addWork(createWork(currentWorkProduced));
+ Thread.sleep(random.nextInt(1000));
+ }
+
+ // correct last increment
+ workProduced.decrementAndGet();
+ IOUtil.OUT().println("work producer " + this + " stopped its production");
+ }
+ catch (InterruptedException ex)
+ {
+ return;
+ }
+ }
+
+ /**
+ * Creates a working unit (runnable).
+ *
+ * @param id
+ * the id
+ * @return the runnable
+ */
+ protected abstract Runnable createWork(int id);
+ }
+
+ /**
+ * A simple work unit to be executed in the queueWorker.
+ *
+ * @author Andre Dietisheim
+ */
+ class Work implements Runnable
+ {
+ private final int id;
+
+ private Work(int id)
+ {
+ this.id = id;
+ IOUtil.OUT().println("work unit " + id + " created");
+ }
+
+ public void run()
+ {
+ workConsumedLatch.countDown();
+ IOUtil.OUT().println("work unit " + id + " consumed");
+ }
+ }
+
+ @Override
+ public void setUp()
+ {
+ threadPool = Executors.newFixedThreadPool(NUM_WORKPRODUCER_THREADS);
+ workConsumedLatch = new CountDownLatch(NUM_WORK);
+ queueWorker = new QueueWorkerWorkSerializer();
+ workProduced = new AtomicInteger(0);
+ }
+
+ @Override
+ public void tearDown()
+ {
+ threadPool.shutdown();
+ queueWorker.dispose();
+ }
+}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/ReferenceValueMapTest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/ReferenceValueMapTest.java
index 82672001f9..2e3776c049 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/ReferenceValueMapTest.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/ReferenceValueMapTest.java
@@ -1,43 +1,43 @@
-/*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- */
-package org.eclipse.net4j.util.tests;
-
-import org.eclipse.net4j.util.ref.ReferenceValueMap;
-
-/**
- * @author Eike Stepper
- */
-public class ReferenceValueMapTest extends AbstractOMTest
-{
- public void testSameKey() throws Exception
- {
- ReferenceValueMap<String, Object> map = new ReferenceValueMap.Weak<String, Object>();
- for (int i = 0; i < 10; i++)
- {
- map.put("SIMON", new Object()); //$NON-NLS-1$
- System.gc();
- map.put("SIMON", new Object()); //$NON-NLS-1$
- assertEquals(true, map.size() >= 0);
- }
- }
-
- public void testDifferentKey() throws Exception
- {
- ReferenceValueMap<String, Object> map = new ReferenceValueMap.Weak<String, Object>();
- for (int i = 0; i < 10; i++)
- {
- map.put("SIMON", new Object()); //$NON-NLS-1$
- System.gc();
- map.put("SIMON2", new Object()); //$NON-NLS-1$
- assertEquals(true, map.size() >= 1);
- }
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.util.tests;
+
+import org.eclipse.net4j.util.ref.ReferenceValueMap;
+
+/**
+ * @author Eike Stepper
+ */
+public class ReferenceValueMapTest extends AbstractOMTest
+{
+ public void testSameKey() throws Exception
+ {
+ ReferenceValueMap<String, Object> map = new ReferenceValueMap.Weak<String, Object>();
+ for (int i = 0; i < 10; i++)
+ {
+ map.put("SIMON", new Object()); //$NON-NLS-1$
+ System.gc();
+ map.put("SIMON", new Object()); //$NON-NLS-1$
+ assertEquals(true, map.size() >= 0);
+ }
+ }
+
+ public void testDifferentKey() throws Exception
+ {
+ ReferenceValueMap<String, Object> map = new ReferenceValueMap.Weak<String, Object>();
+ for (int i = 0; i < 10; i++)
+ {
+ map.put("SIMON", new Object()); //$NON-NLS-1$
+ System.gc();
+ map.put("SIMON2", new Object()); //$NON-NLS-1$
+ assertEquals(true, map.size() >= 1);
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/SecurityTest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/SecurityTest.java
index 8266f14025..77e9fc34ad 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/SecurityTest.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/SecurityTest.java
@@ -1,241 +1,241 @@
-/*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- */
-package org.eclipse.net4j.util.tests;
-
-import org.eclipse.net4j.util.WrappedException;
-import org.eclipse.net4j.util.security.ChallengeNegotiator;
-import org.eclipse.net4j.util.security.IChallengeResponse;
-import org.eclipse.net4j.util.security.IPasswordCredentialsProvider;
-import org.eclipse.net4j.util.security.NegotiationContext;
-import org.eclipse.net4j.util.security.PasswordCredentials;
-import org.eclipse.net4j.util.security.PasswordCredentialsProvider;
-import org.eclipse.net4j.util.security.Randomizer;
-import org.eclipse.net4j.util.security.ResponseNegotiator;
-import org.eclipse.net4j.util.security.UserManager;
-
-import java.nio.ByteBuffer;
-import java.util.concurrent.BlockingQueue;
-import java.util.concurrent.LinkedBlockingQueue;
-import java.util.concurrent.TimeUnit;
-
-/**
- * @author Eike Stepper
- */
-public class SecurityTest extends AbstractOMTest
-{
- private static final int TIMEOUT = 1000;
-
- private static final String USER_ID = "stepper"; //$NON-NLS-1$
-
- private static final char[] PASSWORD1 = "eike2007".toCharArray(); //$NON-NLS-1$
-
- private static final char[] PASSWORD2 = "invalid".toCharArray(); //$NON-NLS-1$
-
- private static final PasswordCredentials CREDENTIALS = new PasswordCredentials(USER_ID, PASSWORD1);
-
- private IPasswordCredentialsProvider credentialsProvider = new PasswordCredentialsProvider(CREDENTIALS);
-
- public void testRandomizerAcceptsSeedsBeforeActivation()
- {
- Randomizer randomizer = new Randomizer();
- randomizer.setSeed(2l);
- }
-
- public void testSuccess() throws Exception
- {
- // Prepare randomizer
- Randomizer randomizer = new Randomizer();
- randomizer.activate();
-
- // Prepare user manager
- UserManager userManager = new UserManager();
- userManager.activate();
- userManager.addUser(USER_ID, PASSWORD1);
-
- // Create negotiation contexts
- PeerNegotiationContext challengeContext = new PeerNegotiationContext();
- PeerNegotiationContext responseContext = new PeerNegotiationContext();
-
- // Prepare challenge context
- challengeContext.setPeer(responseContext);
- Thread challengeThread = new Thread(challengeContext, "challengeThread"); //$NON-NLS-1$
- challengeThread.start();
-
- // Prepare response context
- responseContext.setPeer(challengeContext);
- Thread responseThread = new Thread(responseContext, "responseThread"); //$NON-NLS-1$
- responseThread.start();
-
- // Prepare response negotiator
- ResponseNegotiator responseNegotiator = new ResponseNegotiator();
- responseNegotiator.setCredentialsProvider(credentialsProvider);
- responseNegotiator.activate();
- responseNegotiator.negotiate(responseContext);
-
- // Prepare challenge negotiator
- ChallengeNegotiator challengeNegotiator = new ChallengeNegotiator();
- challengeNegotiator.setRandomizer(randomizer);
- challengeNegotiator.setUserManager(userManager);
- challengeNegotiator.activate();
- challengeNegotiator.negotiate(challengeContext);
-
- Enum<?> responseState = responseContext.waitUntilFinished(TIMEOUT);
- assertEquals(IChallengeResponse.State.SUCCESS, responseState);
-
- Enum<?> challengeState = challengeContext.waitUntilFinished(TIMEOUT);
- assertEquals(IChallengeResponse.State.SUCCESS, challengeState);
-
- challengeContext.deactivate();
- responseContext.deactivate();
- challengeNegotiator.deactivate();
- responseNegotiator.deactivate();
- userManager.deactivate();
- randomizer.deactivate();
- }
-
- public void testFailure() throws Exception
- {
- // Prepare randomizer
- Randomizer randomizer = new Randomizer();
- randomizer.activate();
-
- // Prepare user manager
- UserManager userManager = new UserManager();
- userManager.activate();
- userManager.addUser(USER_ID, PASSWORD2);
-
- // Create negotiation contexts
- PeerNegotiationContext challengeContext = new PeerNegotiationContext();
- PeerNegotiationContext responseContext = new PeerNegotiationContext();
-
- // Prepare challenge context
- challengeContext.setPeer(responseContext);
- Thread challengeThread = new Thread(challengeContext, "challengeThread"); //$NON-NLS-1$
- challengeThread.start();
-
- // Prepare response context
- responseContext.setPeer(challengeContext);
- Thread responseThread = new Thread(responseContext, "responseThread"); //$NON-NLS-1$
- responseThread.start();
-
- // Prepare response negotiator
- ResponseNegotiator responseNegotiator = new ResponseNegotiator();
- responseNegotiator.setCredentialsProvider(credentialsProvider);
- responseNegotiator.activate();
- responseNegotiator.negotiate(responseContext);
-
- // Prepare challenge negotiator
- ChallengeNegotiator challengeNegotiator = new ChallengeNegotiator();
- challengeNegotiator.setRandomizer(randomizer);
- challengeNegotiator.setUserManager(userManager);
- challengeNegotiator.activate();
- challengeNegotiator.negotiate(challengeContext);
-
- Enum<?> responseState = responseContext.waitUntilFinished(TIMEOUT);
- assertEquals(IChallengeResponse.State.FAILURE, responseState);
-
- Enum<?> challengeState = challengeContext.waitUntilFinished(TIMEOUT);
- assertEquals(IChallengeResponse.State.FAILURE, challengeState);
-
- challengeContext.deactivate();
- responseContext.deactivate();
- challengeNegotiator.deactivate();
- responseNegotiator.deactivate();
- userManager.deactivate();
- randomizer.deactivate();
- }
-
- /**
- * @author Eike Stepper
- */
- private final class PeerNegotiationContext extends NegotiationContext implements Runnable
- {
- private PeerNegotiationContext peer;
-
- private String userID;
-
- private BlockingQueue<ByteBuffer> queue = new LinkedBlockingQueue<ByteBuffer>();
-
- private boolean running;
-
- public PeerNegotiationContext()
- {
- }
-
- @SuppressWarnings("unused")
- public PeerNegotiationContext getPeer()
- {
- return peer;
- }
-
- public void setPeer(PeerNegotiationContext peer)
- {
- this.peer = peer;
- }
-
- @SuppressWarnings("unused")
- public String getUserID()
- {
- return userID;
- }
-
- public void setUserID(String userID)
- {
- this.userID = userID;
- }
-
- public ByteBuffer getBuffer()
- {
- return ByteBuffer.allocateDirect(4096);
- }
-
- public void transmitBuffer(ByteBuffer buffer)
- {
- buffer.flip();
- queue.add(buffer);
- }
-
- public void deactivate()
- {
- running = false;
- }
-
- public void run()
- {
- running = true;
- while (running)
- {
- if (peer != null)
- {
- Receiver receiver = peer.getReceiver();
- if (receiver != null)
- {
- ByteBuffer buffer = null;
-
- try
- {
- buffer = queue.poll(20, TimeUnit.MILLISECONDS);
- }
- catch (InterruptedException ex)
- {
- throw WrappedException.wrap(ex);
- }
-
- if (buffer != null)
- {
- receiver.receiveBuffer(peer, buffer);
- }
- }
- }
- }
- }
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.util.tests;
+
+import org.eclipse.net4j.util.WrappedException;
+import org.eclipse.net4j.util.security.ChallengeNegotiator;
+import org.eclipse.net4j.util.security.IChallengeResponse;
+import org.eclipse.net4j.util.security.IPasswordCredentialsProvider;
+import org.eclipse.net4j.util.security.NegotiationContext;
+import org.eclipse.net4j.util.security.PasswordCredentials;
+import org.eclipse.net4j.util.security.PasswordCredentialsProvider;
+import org.eclipse.net4j.util.security.Randomizer;
+import org.eclipse.net4j.util.security.ResponseNegotiator;
+import org.eclipse.net4j.util.security.UserManager;
+
+import java.nio.ByteBuffer;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * @author Eike Stepper
+ */
+public class SecurityTest extends AbstractOMTest
+{
+ private static final int TIMEOUT = 1000;
+
+ private static final String USER_ID = "stepper"; //$NON-NLS-1$
+
+ private static final char[] PASSWORD1 = "eike2007".toCharArray(); //$NON-NLS-1$
+
+ private static final char[] PASSWORD2 = "invalid".toCharArray(); //$NON-NLS-1$
+
+ private static final PasswordCredentials CREDENTIALS = new PasswordCredentials(USER_ID, PASSWORD1);
+
+ private IPasswordCredentialsProvider credentialsProvider = new PasswordCredentialsProvider(CREDENTIALS);
+
+ public void testRandomizerAcceptsSeedsBeforeActivation()
+ {
+ Randomizer randomizer = new Randomizer();
+ randomizer.setSeed(2l);
+ }
+
+ public void testSuccess() throws Exception
+ {
+ // Prepare randomizer
+ Randomizer randomizer = new Randomizer();
+ randomizer.activate();
+
+ // Prepare user manager
+ UserManager userManager = new UserManager();
+ userManager.activate();
+ userManager.addUser(USER_ID, PASSWORD1);
+
+ // Create negotiation contexts
+ PeerNegotiationContext challengeContext = new PeerNegotiationContext();
+ PeerNegotiationContext responseContext = new PeerNegotiationContext();
+
+ // Prepare challenge context
+ challengeContext.setPeer(responseContext);
+ Thread challengeThread = new Thread(challengeContext, "challengeThread"); //$NON-NLS-1$
+ challengeThread.start();
+
+ // Prepare response context
+ responseContext.setPeer(challengeContext);
+ Thread responseThread = new Thread(responseContext, "responseThread"); //$NON-NLS-1$
+ responseThread.start();
+
+ // Prepare response negotiator
+ ResponseNegotiator responseNegotiator = new ResponseNegotiator();
+ responseNegotiator.setCredentialsProvider(credentialsProvider);
+ responseNegotiator.activate();
+ responseNegotiator.negotiate(responseContext);
+
+ // Prepare challenge negotiator
+ ChallengeNegotiator challengeNegotiator = new ChallengeNegotiator();
+ challengeNegotiator.setRandomizer(randomizer);
+ challengeNegotiator.setUserManager(userManager);
+ challengeNegotiator.activate();
+ challengeNegotiator.negotiate(challengeContext);
+
+ Enum<?> responseState = responseContext.waitUntilFinished(TIMEOUT);
+ assertEquals(IChallengeResponse.State.SUCCESS, responseState);
+
+ Enum<?> challengeState = challengeContext.waitUntilFinished(TIMEOUT);
+ assertEquals(IChallengeResponse.State.SUCCESS, challengeState);
+
+ challengeContext.deactivate();
+ responseContext.deactivate();
+ challengeNegotiator.deactivate();
+ responseNegotiator.deactivate();
+ userManager.deactivate();
+ randomizer.deactivate();
+ }
+
+ public void testFailure() throws Exception
+ {
+ // Prepare randomizer
+ Randomizer randomizer = new Randomizer();
+ randomizer.activate();
+
+ // Prepare user manager
+ UserManager userManager = new UserManager();
+ userManager.activate();
+ userManager.addUser(USER_ID, PASSWORD2);
+
+ // Create negotiation contexts
+ PeerNegotiationContext challengeContext = new PeerNegotiationContext();
+ PeerNegotiationContext responseContext = new PeerNegotiationContext();
+
+ // Prepare challenge context
+ challengeContext.setPeer(responseContext);
+ Thread challengeThread = new Thread(challengeContext, "challengeThread"); //$NON-NLS-1$
+ challengeThread.start();
+
+ // Prepare response context
+ responseContext.setPeer(challengeContext);
+ Thread responseThread = new Thread(responseContext, "responseThread"); //$NON-NLS-1$
+ responseThread.start();
+
+ // Prepare response negotiator
+ ResponseNegotiator responseNegotiator = new ResponseNegotiator();
+ responseNegotiator.setCredentialsProvider(credentialsProvider);
+ responseNegotiator.activate();
+ responseNegotiator.negotiate(responseContext);
+
+ // Prepare challenge negotiator
+ ChallengeNegotiator challengeNegotiator = new ChallengeNegotiator();
+ challengeNegotiator.setRandomizer(randomizer);
+ challengeNegotiator.setUserManager(userManager);
+ challengeNegotiator.activate();
+ challengeNegotiator.negotiate(challengeContext);
+
+ Enum<?> responseState = responseContext.waitUntilFinished(TIMEOUT);
+ assertEquals(IChallengeResponse.State.FAILURE, responseState);
+
+ Enum<?> challengeState = challengeContext.waitUntilFinished(TIMEOUT);
+ assertEquals(IChallengeResponse.State.FAILURE, challengeState);
+
+ challengeContext.deactivate();
+ responseContext.deactivate();
+ challengeNegotiator.deactivate();
+ responseNegotiator.deactivate();
+ userManager.deactivate();
+ randomizer.deactivate();
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ private final class PeerNegotiationContext extends NegotiationContext implements Runnable
+ {
+ private PeerNegotiationContext peer;
+
+ private String userID;
+
+ private BlockingQueue<ByteBuffer> queue = new LinkedBlockingQueue<ByteBuffer>();
+
+ private boolean running;
+
+ public PeerNegotiationContext()
+ {
+ }
+
+ @SuppressWarnings("unused")
+ public PeerNegotiationContext getPeer()
+ {
+ return peer;
+ }
+
+ public void setPeer(PeerNegotiationContext peer)
+ {
+ this.peer = peer;
+ }
+
+ @SuppressWarnings("unused")
+ public String getUserID()
+ {
+ return userID;
+ }
+
+ public void setUserID(String userID)
+ {
+ this.userID = userID;
+ }
+
+ public ByteBuffer getBuffer()
+ {
+ return ByteBuffer.allocateDirect(4096);
+ }
+
+ public void transmitBuffer(ByteBuffer buffer)
+ {
+ buffer.flip();
+ queue.add(buffer);
+ }
+
+ public void deactivate()
+ {
+ running = false;
+ }
+
+ public void run()
+ {
+ running = true;
+ while (running)
+ {
+ if (peer != null)
+ {
+ Receiver receiver = peer.getReceiver();
+ if (receiver != null)
+ {
+ ByteBuffer buffer = null;
+
+ try
+ {
+ buffer = queue.poll(20, TimeUnit.MILLISECONDS);
+ }
+ catch (InterruptedException ex)
+ {
+ throw WrappedException.wrap(ex);
+ }
+
+ if (buffer != null)
+ {
+ receiver.receiveBuffer(peer, buffer);
+ }
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/SortedFileMapTest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/SortedFileMapTest.java
index 6d09f96972..72404d7afe 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/SortedFileMapTest.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/SortedFileMapTest.java
@@ -1,108 +1,108 @@
-/*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- */
-package org.eclipse.net4j.util.tests;
-
-import org.eclipse.net4j.util.io.ExtendedDataInput;
-import org.eclipse.net4j.util.io.ExtendedDataOutput;
-import org.eclipse.net4j.util.io.IOUtil;
-import org.eclipse.net4j.util.io.SortedFileMap;
-
-import java.io.File;
-import java.io.IOException;
-
-/**
- * @author Eike Stepper
- */
-public class SortedFileMapTest extends AbstractOMTest
-{
- public void testMap() throws Exception
- {
- File file = new File("testMap.dat"); //$NON-NLS-1$
- if (file.exists())
- {
- file.delete();
- }
-
- SortedFileMap<Integer, String> map = null;
-
- try
- {
- map = new TestMap(file);
- for (int i = 0; i < 500; i++)
- {
- map.put(i, "Value " + i); //$NON-NLS-1$
- }
-
- for (int i = 0; i < 500; i++)
- {
- String value = map.get(i);
- IOUtil.OUT().println(value);
- }
- }
- finally
- {
- IOUtil.close(map);
- }
- }
-
- /**
- * @author Eike Stepper
- */
- public static final class TestMap extends SortedFileMap<Integer, String>
- {
- public TestMap(File file)
- {
- super(file, "rw"); //$NON-NLS-1$
- }
-
- @Override
- public int getKeySize()
- {
- return 4;
- }
-
- @Override
- protected Integer readKey(ExtendedDataInput in) throws IOException
- {
- return in.readInt();
- }
-
- @Override
- protected void writeKey(ExtendedDataOutput out, Integer key) throws IOException
- {
- out.writeInt(key);
- }
-
- @Override
- public int getValueSize()
- {
- return 20;
- }
-
- @Override
- protected String readValue(ExtendedDataInput in) throws IOException
- {
- return in.readString();
- }
-
- @Override
- protected void writeValue(ExtendedDataOutput out, String value) throws IOException
- {
- byte[] bytes = value.getBytes();
- if (bytes.length + 4 > getValueSize())
- {
- throw new IllegalArgumentException("Value size of " + getValueSize() + " exceeded: " + value); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- out.writeByteArray(bytes);
- }
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.util.tests;
+
+import org.eclipse.net4j.util.io.ExtendedDataInput;
+import org.eclipse.net4j.util.io.ExtendedDataOutput;
+import org.eclipse.net4j.util.io.IOUtil;
+import org.eclipse.net4j.util.io.SortedFileMap;
+
+import java.io.File;
+import java.io.IOException;
+
+/**
+ * @author Eike Stepper
+ */
+public class SortedFileMapTest extends AbstractOMTest
+{
+ public void testMap() throws Exception
+ {
+ File file = new File("testMap.dat"); //$NON-NLS-1$
+ if (file.exists())
+ {
+ file.delete();
+ }
+
+ SortedFileMap<Integer, String> map = null;
+
+ try
+ {
+ map = new TestMap(file);
+ for (int i = 0; i < 500; i++)
+ {
+ map.put(i, "Value " + i); //$NON-NLS-1$
+ }
+
+ for (int i = 0; i < 500; i++)
+ {
+ String value = map.get(i);
+ IOUtil.OUT().println(value);
+ }
+ }
+ finally
+ {
+ IOUtil.close(map);
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static final class TestMap extends SortedFileMap<Integer, String>
+ {
+ public TestMap(File file)
+ {
+ super(file, "rw"); //$NON-NLS-1$
+ }
+
+ @Override
+ public int getKeySize()
+ {
+ return 4;
+ }
+
+ @Override
+ protected Integer readKey(ExtendedDataInput in) throws IOException
+ {
+ return in.readInt();
+ }
+
+ @Override
+ protected void writeKey(ExtendedDataOutput out, Integer key) throws IOException
+ {
+ out.writeInt(key);
+ }
+
+ @Override
+ public int getValueSize()
+ {
+ return 20;
+ }
+
+ @Override
+ protected String readValue(ExtendedDataInput in) throws IOException
+ {
+ return in.readString();
+ }
+
+ @Override
+ protected void writeValue(ExtendedDataOutput out, String value) throws IOException
+ {
+ byte[] bytes = value.getBytes();
+ if (bytes.length + 4 > getValueSize())
+ {
+ throw new IllegalArgumentException("Value size of " + getValueSize() + " exceeded: " + value); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ out.writeByteArray(bytes);
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/StreamWrapperTest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/StreamWrapperTest.java
index a17739f089..f3094846ae 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/StreamWrapperTest.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/StreamWrapperTest.java
@@ -1,46 +1,46 @@
-/*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- */
-package org.eclipse.net4j.util.tests;
-
-import org.eclipse.net4j.util.io.XORInputStream;
-import org.eclipse.net4j.util.io.XOROutputStream;
-
-import java.io.BufferedReader;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.InputStreamReader;
-import java.io.PrintStream;
-
-/**
- * @author Eike Stepper
- */
-public class StreamWrapperTest extends AbstractOMTest
-{
- public void testXORStreams() throws Exception
- {
- int[] key = { 1, 2, 3, 4 };
-
- ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
- XOROutputStream xorOutputStream = new XOROutputStream(byteArrayOutputStream, key);
- PrintStream printStream = new PrintStream(xorOutputStream);
- printStream.println("Hello world!");
- printStream.println("Hello world!");
-
- XORInputStream xorInputStream = new XORInputStream(new ByteArrayInputStream(byteArrayOutputStream.toByteArray()),
- key);
-
- InputStreamReader inputStreamReader = new InputStreamReader(xorInputStream);
- BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
-
- assertEquals("Hello world!", bufferedReader.readLine());
- assertEquals("Hello world!", bufferedReader.readLine());
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.util.tests;
+
+import org.eclipse.net4j.util.io.XORInputStream;
+import org.eclipse.net4j.util.io.XOROutputStream;
+
+import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.InputStreamReader;
+import java.io.PrintStream;
+
+/**
+ * @author Eike Stepper
+ */
+public class StreamWrapperTest extends AbstractOMTest
+{
+ public void testXORStreams() throws Exception
+ {
+ int[] key = { 1, 2, 3, 4 };
+
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ XOROutputStream xorOutputStream = new XOROutputStream(byteArrayOutputStream, key);
+ PrintStream printStream = new PrintStream(xorOutputStream);
+ printStream.println("Hello world!");
+ printStream.println("Hello world!");
+
+ XORInputStream xorInputStream = new XORInputStream(new ByteArrayInputStream(byteArrayOutputStream.toByteArray()),
+ key);
+
+ InputStreamReader inputStreamReader = new InputStreamReader(xorInputStream);
+ BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
+
+ assertEquals("Hello world!", bufferedReader.readLine());
+ assertEquals("Hello world!", bufferedReader.readLine());
+ }
+}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/StringCompressorTest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/StringCompressorTest.java
index c98818e5d3..539c517b2c 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/StringCompressorTest.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/StringCompressorTest.java
@@ -1,291 +1,291 @@
-/*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- */
-package org.eclipse.net4j.util.tests;
-
-import org.eclipse.net4j.util.io.ExtendedDataInput;
-import org.eclipse.net4j.util.io.ExtendedDataInputStream;
-import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
-import org.eclipse.net4j.util.io.StringCompressor;
-
-import java.io.IOException;
-import java.io.PipedInputStream;
-import java.io.PipedOutputStream;
-import java.util.Random;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-
-/**
- * @author Eike Stepper
- */
-public class StringCompressorTest extends AbstractOMTest
-{
- private static long SLEEP_WRITER = 1;
-
- private static long SLEEP_READER = 0;
-
- private static final String[] strings = createStrings(50, 837456);
-
- private static final int[] indices = createIndices(100, 50, 9087346);
-
- private StringCompressor.Counting client;
-
- private StringCompressor.Counting server;
-
- public void testSingleStreamToServer() throws Exception
- {
- run(1, 0);
- }
-
- public void testSingleStreamToClient() throws Exception
- {
- run(0, 1);
- }
-
- public void testBidi1() throws Exception
- {
- run(1, 1);
- }
-
- public void testBidi10() throws Exception
- {
- run(10, 10);
- }
-
- public void testBidi1Plus10() throws Exception
- {
- run(1, 1);
- run(10, 10);
- }
-
- @Override
- protected void doSetUp() throws Exception
- {
- super.doSetUp();
- client = new StringCompressor.Counting(true);
- server = new StringCompressor.Counting(false);
- }
-
- @Override
- protected void doTearDown() throws Exception
- {
- System.out.println("Strings read by client compressor: " + client.getStringsRead());
- System.out.println("Strings read by server compressor: " + server.getStringsRead());
- System.out.println("Strings written by client compressor: " + client.getStringsWritten());
- System.out.println("Strings written by server compressor: " + server.getStringsWritten());
- super.doTearDown();
- }
-
- private void run(int toServer, int toClient) throws IOException, InterruptedException
- {
- CountDownLatch latch = new CountDownLatch(toServer + toClient);
- while (toServer > 0 || toClient > 0)
- {
- if (toServer > 0)
- {
- --toServer;
- new Stream(latch, client, server).start();
- }
-
- if (toClient > 0)
- {
- --toClient;
- new Stream(latch, server, client).start();
- }
- }
-
- latch.await(300, TimeUnit.SECONDS);
- }
-
- private static String[] createStrings(int count, long seed)
- {
- Random random = new Random(seed);
- String[] result = new String[count];
- for (int i = 0; i < result.length; i++)
- {
- String str = "";
- int length = next(random) % 13;
- for (int j = 0; j < length + 1; j++)
- {
- int val = next(random);
- str += Integer.toString(val, 36);
- }
-
- System.out.println(str);
- result[i] = str;
- }
-
- return result;
- }
-
- private static int[] createIndices(int count, int range, long seed)
- {
- Random random = new Random(seed);
- int[] result = new int[count];
- for (int i = 0; i < result.length; i++)
- {
- result[i] = next(random) % range;
- }
-
- return result;
- }
-
- private static int next(Random random)
- {
- for (;;)
- {
- int val = random.nextInt();
- if (val > 0)
- {
- return val;
- }
- }
- }
-
- /**
- * @author Eike Stepper
- */
- public static class Stream extends Thread
- {
- private CountDownLatch latch;
-
- private Writer writer;
-
- private Reader reader;
-
- public Stream(CountDownLatch latch, StringCompressor writer, StringCompressor reader) throws IOException
- {
- this.latch = latch;
- this.writer = new Writer(writer);
- this.reader = new Reader(reader, this.writer);
- }
-
- @Override
- public void run()
- {
- try
- {
- reader.start();
- writer.start();
-
- reader.join();
- writer.join();
-
- latch.countDown();
- }
- catch (Exception ex)
- {
- ex.printStackTrace();
- }
- }
- }
-
- /**
- * @author Eike Stepper
- */
- public static class Writer extends Thread
- {
- private StringCompressor compressor;
-
- private PipedOutputStream pipe;
-
- private Exception exception;
-
- public Writer(StringCompressor compressor)
- {
- this.compressor = compressor;
- pipe = new PipedOutputStream();
- }
-
- public PipedOutputStream getPipe()
- {
- return pipe;
- }
-
- public Exception getException()
- {
- return exception;
- }
-
- @Override
- public void run()
- {
- try
- {
- ExtendedDataOutputStream out = new ExtendedDataOutputStream(pipe);
- for (int i = 0; i < indices.length; i++)
- {
- int index = indices[i];
- msg(getName() + " --> " + i);
- compressor.write(out, strings[index]);
- if (SLEEP_WRITER > 0)
- {
- Thread.sleep(SLEEP_WRITER);
- }
- }
- }
- catch (Exception ex)
- {
- exception = ex;
- ex.printStackTrace();
- }
- }
- }
-
- /**
- * @author Eike Stepper
- */
- public static class Reader extends Thread
- {
- private StringCompressor compressor;
-
- private PipedInputStream pipe;
-
- private Exception exception;
-
- public Reader(StringCompressor compressor, Writer writer) throws IOException
- {
- this.compressor = compressor;
- pipe = new PipedInputStream(writer.getPipe());
- }
-
- public Exception getException()
- {
- return exception;
- }
-
- @Override
- public void run()
- {
- try
- {
- ExtendedDataInput in = new ExtendedDataInputStream(pipe);
- for (int i = 0; i < indices.length; i++)
- {
- int index = indices[i];
- msg(getName() + " --> " + i);
- String toBeRead = strings[index];
-
- String read = compressor.read(in);
- assertEquals(toBeRead, read);
- if (SLEEP_READER > 0)
- {
- Thread.sleep(SLEEP_READER);
- }
- }
- }
- catch (Exception ex)
- {
- exception = ex;
- ex.printStackTrace();
- }
- }
- }
-}
+/*
+ * Copyright (c) 2004 - 2012 Eike Stepper (Berlin, Germany) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.net4j.util.tests;
+
+import org.eclipse.net4j.util.io.ExtendedDataInput;
+import org.eclipse.net4j.util.io.ExtendedDataInputStream;
+import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
+import org.eclipse.net4j.util.io.StringCompressor;
+
+import java.io.IOException;
+import java.io.PipedInputStream;
+import java.io.PipedOutputStream;
+import java.util.Random;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * @author Eike Stepper
+ */
+public class StringCompressorTest extends AbstractOMTest
+{
+ private static long SLEEP_WRITER = 1;
+
+ private static long SLEEP_READER = 0;
+
+ private static final String[] strings = createStrings(50, 837456);
+
+ private static final int[] indices = createIndices(100, 50, 9087346);
+
+ private StringCompressor.Counting client;
+
+ private StringCompressor.Counting server;
+
+ public void testSingleStreamToServer() throws Exception
+ {
+ run(1, 0);
+ }
+
+ public void testSingleStreamToClient() throws Exception
+ {
+ run(0, 1);
+ }
+
+ public void testBidi1() throws Exception
+ {
+ run(1, 1);
+ }
+
+ public void testBidi10() throws Exception
+ {
+ run(10, 10);
+ }
+
+ public void testBidi1Plus10() throws Exception
+ {
+ run(1, 1);
+ run(10, 10);
+ }
+
+ @Override
+ protected void doSetUp() throws Exception
+ {
+ super.doSetUp();
+ client = new StringCompressor.Counting(true);
+ server = new StringCompressor.Counting(false);
+ }
+
+ @Override
+ protected void doTearDown() throws Exception
+ {
+ System.out.println("Strings read by client compressor: " + client.getStringsRead());
+ System.out.println("Strings read by server compressor: " + server.getStringsRead());
+ System.out.println("Strings written by client compressor: " + client.getStringsWritten());
+ System.out.println("Strings written by server compressor: " + server.getStringsWritten());
+ super.doTearDown();
+ }
+
+ private void run(int toServer, int toClient) throws IOException, InterruptedException
+ {
+ CountDownLatch latch = new CountDownLatch(toServer + toClient);
+ while (toServer > 0 || toClient > 0)
+ {
+ if (toServer > 0)
+ {
+ --toServer;
+ new Stream(latch, client, server).start();
+ }
+
+ if (toClient > 0)
+ {
+ --toClient;
+ new Stream(latch, server, client).start();
+ }
+ }
+
+ latch.await(300, TimeUnit.SECONDS);
+ }
+
+ private static String[] createStrings(int count, long seed)
+ {
+ Random random = new Random(seed);
+ String[] result = new String[count];
+ for (int i = 0; i < result.length; i++)
+ {
+ String str = "";
+ int length = next(random) % 13;
+ for (int j = 0; j < length + 1; j++)
+ {
+ int val = next(random);
+ str += Integer.toString(val, 36);
+ }
+
+ System.out.println(str);
+ result[i] = str;
+ }
+
+ return result;
+ }
+
+ private static int[] createIndices(int count, int range, long seed)
+ {
+ Random random = new Random(seed);
+ int[] result = new int[count];
+ for (int i = 0; i < result.length; i++)
+ {
+ result[i] = next(random) % range;
+ }
+
+ return result;
+ }
+
+ private static int next(Random random)
+ {
+ for (;;)
+ {
+ int val = random.nextInt();
+ if (val > 0)
+ {
+ return val;
+ }
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static class Stream extends Thread
+ {
+ private CountDownLatch latch;
+
+ private Writer writer;
+
+ private Reader reader;
+
+ public Stream(CountDownLatch latch, StringCompressor writer, StringCompressor reader) throws IOException
+ {
+ this.latch = latch;
+ this.writer = new Writer(writer);
+ this.reader = new Reader(reader, this.writer);
+ }
+
+ @Override
+ public void run()
+ {
+ try
+ {
+ reader.start();
+ writer.start();
+
+ reader.join();
+ writer.join();
+
+ latch.countDown();
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static class Writer extends Thread
+ {
+ private StringCompressor compressor;
+
+ private PipedOutputStream pipe;
+
+ private Exception exception;
+
+ public Writer(StringCompressor compressor)
+ {
+ this.compressor = compressor;
+ pipe = new PipedOutputStream();
+ }
+
+ public PipedOutputStream getPipe()
+ {
+ return pipe;
+ }
+
+ public Exception getException()
+ {
+ return exception;
+ }
+
+ @Override
+ public void run()
+ {
+ try
+ {
+ ExtendedDataOutputStream out = new ExtendedDataOutputStream(pipe);
+ for (int i = 0; i < indices.length; i++)
+ {
+ int index = indices[i];
+ msg(getName() + " --> " + i);
+ compressor.write(out, strings[index]);
+ if (SLEEP_WRITER > 0)
+ {
+ Thread.sleep(SLEEP_WRITER);
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ exception = ex;
+ ex.printStackTrace();
+ }
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static class Reader extends Thread
+ {
+ private StringCompressor compressor;
+
+ private PipedInputStream pipe;
+
+ private Exception exception;
+
+ public Reader(StringCompressor compressor, Writer writer) throws IOException
+ {
+ this.compressor = compressor;
+ pipe = new PipedInputStream(writer.getPipe());
+ }
+
+ public Exception getException()
+ {
+ return exception;
+ }
+
+ @Override
+ public void run()
+ {
+ try
+ {
+ ExtendedDataInput in = new ExtendedDataInputStream(pipe);
+ for (int i = 0; i < indices.length; i++)
+ {
+ int index = indices[i];
+ msg(getName() + " --> " + i);
+ String toBeRead = strings[index];
+
+ String read = compressor.read(in);
+ assertEquals(toBeRead, read);
+ if (SLEEP_READER > 0)
+ {
+ Thread.sleep(SLEEP_READER);
+ }
+ }
+ }
+ catch (Exception ex)
+ {
+ exception = ex;
+ ex.printStackTrace();
+ }
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/SynchronizingCorrelatorTest.java b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/SynchronizingCorrelatorTest.java
index c02c00011e..9e8a078a3e 100644
--- a/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/SynchronizingCorrelatorTest.java
+++ b/plugins/org.eclipse.net4j.tests/src/org/eclipse/net4j/util/tests/SynchronizingCorrelatorTest.java
@@ -1,151 +1,151 @@
-/*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- */
-package org.eclipse.net4j.util.tests;
-
-import org.eclipse.net4j.util.concurrent.ISynchronizer;
-import org.eclipse.net4j.util.concurrent.SynchronizingCorrelator;
-
-/**
- * @author Eike Stepper
- */
-public class SynchronizingCorrelatorTest extends AbstractOMTest
-{
- public void testPutConsumerFirst() throws Exception
- {
- final Boolean[] result = { false };
- final SynchronizingCorrelator<String, Boolean> correlator = new SynchronizingCorrelator<String, Boolean>();
- final Thread consumer = new Thread()
- {
- @Override
- public void run()
- {
- ISynchronizer<Boolean> eike = correlator.correlate("eike"); //$NON-NLS-1$
- result[0] = eike.get(5000);
- msg("RESULT: " + result[0]); //$NON-NLS-1$
- }
- };
-
- consumer.start();
- sleep(100);
-
- correlator.put("eike", true, DEFAULT_TIMEOUT); //$NON-NLS-1$
- consumer.join(DEFAULT_TIMEOUT);
- assertEquals(Boolean.TRUE, result[0]);
- }
-
- public void testPutConsumerFirst10() throws Exception
- {
- for (int i = 0; i < 10; i++)
- {
- testPutConsumerFirst();
- }
- }
-
- public void testBlockingPutConsumerFirst() throws Exception
- {
- final Boolean[] result = { false };
- final SynchronizingCorrelator<String, Boolean> correlator = new SynchronizingCorrelator<String, Boolean>();
- final Thread consumer = new Thread()
- {
- @Override
- public void run()
- {
- ISynchronizer<Boolean> eike = correlator.correlate("eike"); //$NON-NLS-1$
- result[0] = eike.get(5000);
- msg("RESULT: " + result[0]); //$NON-NLS-1$
- }
- };
-
- consumer.start();
- Thread.sleep(10);
-
- boolean consumed = correlator.put("eike", true, 1000); //$NON-NLS-1$
- msg("Consumed: " + consumed); //$NON-NLS-1$
- assertEquals(true, consumed);
-
- consumer.join(1000);
- assertEquals(Boolean.TRUE, result[0]);
- }
-
- public void testBlockingPutConsumerFirst10() throws Exception
- {
- for (int i = 0; i < 10; i++)
- {
- testBlockingPutConsumerFirst();
- }
- }
-
- public void _testPutProducerFirst() throws Exception
- {
- final Boolean[] result = { false };
- final SynchronizingCorrelator<String, Boolean> correlator = new SynchronizingCorrelator<String, Boolean>();
- correlator.put("eike", true, DEFAULT_TIMEOUT); //$NON-NLS-1$
-
- final Thread consumer = new Thread()
- {
- @Override
- public void run()
- {
- ISynchronizer<Boolean> eike = correlator.correlate("eike"); //$NON-NLS-1$
- result[0] = eike.get(5000);
- msg("RESULT: " + result[0]); //$NON-NLS-1$
- }
- };
-
- consumer.start();
- Thread.sleep(10);
-
- consumer.join(100);
- assertEquals(Boolean.TRUE, result[0]);
- }
-