Skip to main content
summaryrefslogtreecommitdiffstats
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
parent7416443692cdda72d1f704ea4fc5ececcc669df7 (diff)
downloadcdo-0266166cb9ff9535c150250073ea1e57b42d2693.tar.gz
cdo-0266166cb9ff9535c150250073ea1e57b42d2693.tar.xz
cdo-0266166cb9ff9535c150250073ea1e57b42d2693.zip
Adjusted copyrights to 2012
Diffstat (limited to 'plugins/org.eclipse.net4j')
-rw-r--r--plugins/org.eclipse.net4j/.settings/org.eclipse.jdt.ui.prefs240
-rw-r--r--plugins/org.eclipse.net4j/about.properties62
-rw-r--r--plugins/org.eclipse.net4j/build.properties56
-rw-r--r--plugins/org.eclipse.net4j/copyright.txt14
-rw-r--r--plugins/org.eclipse.net4j/plugin.properties22
-rw-r--r--plugins/org.eclipse.net4j/plugin.xml76
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/TransportConfig.java248
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/Buffer.java864
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/BufferFactory.java124
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/BufferPool.java486
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/BufferProvider.java138
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/BufferProviderFactory.java86
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/BufferUtil.java274
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/Net4jCommandProvider.java232
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/OM.java130
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/ContainerProtocolProvider.java166
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/FactoriesProtocolProvider.java146
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/ILocationAware.java94
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/ITransportConfig.java114
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/ITransportConfigAware.java70
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/Net4jUtil.java362
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/TransportConfigurator.java334
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/TransportInjector.java220
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/acceptor/IAcceptor.java106
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/acceptor/package-info.java2
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/buffer/BufferInputStream.java458
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/buffer/BufferOutputStream.java508
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/buffer/BufferState.java220
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/buffer/IBuffer.java572
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/buffer/IBufferHandler.java58
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/buffer/IBufferPool.java94
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/buffer/IBufferProvider.java104
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/buffer/package-info.java2
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/channel/ChannelException.java86
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/channel/ChannelInputStream.java154
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/channel/ChannelOutputStream.java72
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/channel/IChannel.java228
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/channel/IChannelMultiplexer.java196
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/channel/package-info.java2
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/connector/ConnectorCredentialsInjector.java206
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/connector/ConnectorException.java80
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/connector/ConnectorState.java184
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/connector/IConnector.java216
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/connector/IConnectorEvent.java64
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/connector/IConnectorStateEvent.java62
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/connector/package-info.java2
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/package-info.java2
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/protocol/IProtocol.java82
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/protocol/IProtocolProvider.java44
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/protocol/package-info.java2
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/ISignalProtocol.java86
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/Indication.java118
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/IndicationWithMonitoring.java344
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/IndicationWithResponse.java212
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/MonitorCanceledIndication.java82
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/MonitorCanceledRequest.java86
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/MonitorProgressIndication.java86
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/MonitorProgressRequest.java102
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/RemoteException.java148
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/RemoteExceptionIndication.java158
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/RemoteExceptionRequest.java194
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/Request.java134
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/RequestWithConfirmation.java282
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/RequestWithMonitoring.java604
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/SetTimeoutIndication.java96
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/SetTimeoutRequest.java100
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/Signal.java706
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/SignalActor.java134
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/SignalCounter.java112
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/SignalFinishedEvent.java128
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/SignalProtocol.java1272
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/SignalReactor.java106
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/SignalScheduledEvent.java100
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/heartbeat/HeartBeatProtocol.java704
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/heartbeat/package-info.java2
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/package-info.java2
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/wrapping/GZIPStreamWrapperInjector.java52
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/wrapping/StreamWrapperInjector.java152
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/wrapping/XORStreamWrapperInjector.java48
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/wrapping/package-info.java2
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/Acceptor.java334
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/AcceptorFactory.java52
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/Channel.java974
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/ChannelMultiplexer.java746
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/ClientProtocolFactory.java54
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/Connector.java860
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/ConnectorFactory.java52
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/InternalAcceptor.java44
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/InternalBuffer.java50
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/InternalChannel.java176
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/InternalChannelMultiplexer.java78
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/InternalConnector.java42
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/Protocol.java354
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/ServerProtocolFactory.java54
-rw-r--r--plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/package-info.java2
95 files changed, 9294 insertions, 9294 deletions
diff --git a/plugins/org.eclipse.net4j/.settings/org.eclipse.jdt.ui.prefs b/plugins/org.eclipse.net4j/.settings/org.eclipse.jdt.ui.prefs
index aaef0ccba1..6726e7034a 100644
--- a/plugins/org.eclipse.net4j/.settings/org.eclipse.jdt.ui.prefs
+++ b/plugins/org.eclipse.net4j/.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/about.properties b/plugins/org.eclipse.net4j/about.properties
index d71522756e..37ffe4875f 100644
--- a/plugins/org.eclipse.net4j/about.properties
+++ b/plugins/org.eclipse.net4j/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 Transport
-featureText = Net4j Signalling Platform Transport\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 Transport
+featureText = Net4j Signalling Platform Transport\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/build.properties b/plugins/org.eclipse.net4j/build.properties
index c85c1ad0be..751454861b 100644
--- a/plugins/org.eclipse.net4j/build.properties
+++ b/plugins/org.eclipse.net4j/build.properties
@@ -1,28 +1,28 @@
-# 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/,\
- .,\
- plugin.properties,\
- .options,\
- about.html,\
- copyright.txt,\
- plugin.xml,\
- about.ini,\
- about.mappings,\
- about.properties,\
- modeling32.png
-src.includes = about.html,\
- copyright.txt
-
-doc.project = org.eclipse.net4j.doc
+# 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/,\
+ .,\
+ plugin.properties,\
+ .options,\
+ about.html,\
+ copyright.txt,\
+ plugin.xml,\
+ about.ini,\
+ about.mappings,\
+ about.properties,\
+ modeling32.png
+src.includes = about.html,\
+ copyright.txt
+
+doc.project = org.eclipse.net4j.doc
diff --git a/plugins/org.eclipse.net4j/copyright.txt b/plugins/org.eclipse.net4j/copyright.txt
index e921242cf0..8f6328980e 100644
--- a/plugins/org.eclipse.net4j/copyright.txt
+++ b/plugins/org.eclipse.net4j/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/plugin.properties b/plugins/org.eclipse.net4j/plugin.properties
index c8f698e9b8..074f4305b8 100644
--- a/plugins/org.eclipse.net4j/plugin.properties
+++ b/plugins/org.eclipse.net4j/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 Transport
-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 Transport
+providerName = Eclipse Modeling Project
diff --git a/plugins/org.eclipse.net4j/plugin.xml b/plugins/org.eclipse.net4j/plugin.xml
index ae9af23e95..a0c52145ae 100644
--- a/plugins/org.eclipse.net4j/plugin.xml
+++ b/plugins/org.eclipse.net4j/plugin.xml
@@ -1,38 +1,38 @@
-<?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.internal.net4j.buffer.BufferProviderFactory"
- productGroup="org.eclipse.net4j.bufferProviders"
- type="default"/>
- <factory
- class="org.eclipse.net4j.signal.heartbeat.HeartBeatProtocol$Server$Factory"
- productGroup="org.eclipse.net4j.serverProtocols"
- type="heartbeat"/>
- </extension>
-
- <extension
- point="org.eclipse.net4j.util.elementProcessors">
- <elementProcessor
- class="org.eclipse.net4j.TransportInjector">
- </elementProcessor>
- <elementProcessor
- class="org.eclipse.net4j.signal.heartbeat.HeartBeatProtocol$Server$TimerInjector">
- </elementProcessor>
- </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.internal.net4j.buffer.BufferProviderFactory"
+ productGroup="org.eclipse.net4j.bufferProviders"
+ type="default"/>
+ <factory
+ class="org.eclipse.net4j.signal.heartbeat.HeartBeatProtocol$Server$Factory"
+ productGroup="org.eclipse.net4j.serverProtocols"
+ type="heartbeat"/>
+ </extension>
+
+ <extension
+ point="org.eclipse.net4j.util.elementProcessors">
+ <elementProcessor
+ class="org.eclipse.net4j.TransportInjector">
+ </elementProcessor>
+ <elementProcessor
+ class="org.eclipse.net4j.signal.heartbeat.HeartBeatProtocol$Server$TimerInjector">
+ </elementProcessor>
+ </extension>
+
+</plugin>
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/TransportConfig.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/TransportConfig.java
index e86f5e8180..43f63fd03c 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/TransportConfig.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/TransportConfig.java
@@ -1,124 +1,124 @@
-/*
- * 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.internal.net4j;
-
-import org.eclipse.net4j.ITransportConfig;
-import org.eclipse.net4j.buffer.IBufferProvider;
-import org.eclipse.net4j.channel.IChannel;
-import org.eclipse.net4j.protocol.IProtocolProvider;
-import org.eclipse.net4j.util.lifecycle.ILifecycle;
-import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
-import org.eclipse.net4j.util.security.INegotiator;
-
-import java.text.MessageFormat;
-import java.util.concurrent.ExecutorService;
-
-/**
- * @author Eike Stepper
- */
-public class TransportConfig implements ITransportConfig
-{
- private transient ILifecycle lifecycle;
-
- private IBufferProvider bufferProvider;
-
- /**
- * An optional executor to be used by the {@link IChannel}s to process their receive queues instead of the current
- * thread. If not <code>null</code> the sender and the receiver peers become decoupled.
- * <p>
- */
- private ExecutorService receiveExecutor;
-
- private IProtocolProvider protocolProvider;
-
- private INegotiator negotiator;
-
- public TransportConfig()
- {
- }
-
- public TransportConfig(ILifecycle lifecycle)
- {
- this.lifecycle = lifecycle;
- }
-
- public TransportConfig(ILifecycle lifecycle, ExecutorService receiveExecutor, IBufferProvider bufferProvider,
- IProtocolProvider protocolProvider, INegotiator negotiator)
- {
- this(lifecycle);
- this.receiveExecutor = receiveExecutor;
- this.bufferProvider = bufferProvider;
- this.protocolProvider = protocolProvider;
- this.negotiator = negotiator;
- }
-
- public ILifecycle getLifecycle()
- {
- return lifecycle;
- }
-
- public void setLifecycle(ILifecycle lifecycle)
- {
- this.lifecycle = lifecycle;
- }
-
- public ExecutorService getReceiveExecutor()
- {
- return receiveExecutor;
- }
-
- public void setReceiveExecutor(ExecutorService receiveExecutor)
- {
- LifecycleUtil.checkInactive(lifecycle);
- this.receiveExecutor = receiveExecutor;
- }
-
- public IBufferProvider getBufferProvider()
- {
- return bufferProvider;
- }
-
- public void setBufferProvider(IBufferProvider bufferProvider)
- {
- LifecycleUtil.checkInactive(lifecycle);
- this.bufferProvider = bufferProvider;
- }
-
- public IProtocolProvider getProtocolProvider()
- {
- return protocolProvider;
- }
-
- public void setProtocolProvider(IProtocolProvider protocolProvider)
- {
- LifecycleUtil.checkInactive(lifecycle);
- this.protocolProvider = protocolProvider;
- }
-
- public INegotiator getNegotiator()
- {
- return negotiator;
- }
-
- public void setNegotiator(INegotiator negotiator)
- {
- LifecycleUtil.checkInactive(lifecycle);
- this.negotiator = negotiator;
- }
-
- @Override
- public String toString()
- {
- return MessageFormat.format(
- "TransportConfig[receiveExecutor={0}, bufferProvider={1}, protocolProvider={2}, negotiator={3}]", //$NON-NLS-1$
- receiveExecutor, bufferProvider, protocolProvider, negotiator);
- }
-}
+/*
+ * 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.internal.net4j;
+
+import org.eclipse.net4j.ITransportConfig;
+import org.eclipse.net4j.buffer.IBufferProvider;
+import org.eclipse.net4j.channel.IChannel;
+import org.eclipse.net4j.protocol.IProtocolProvider;
+import org.eclipse.net4j.util.lifecycle.ILifecycle;
+import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
+import org.eclipse.net4j.util.security.INegotiator;
+
+import java.text.MessageFormat;
+import java.util.concurrent.ExecutorService;
+
+/**
+ * @author Eike Stepper
+ */
+public class TransportConfig implements ITransportConfig
+{
+ private transient ILifecycle lifecycle;
+
+ private IBufferProvider bufferProvider;
+
+ /**
+ * An optional executor to be used by the {@link IChannel}s to process their receive queues instead of the current
+ * thread. If not <code>null</code> the sender and the receiver peers become decoupled.
+ * <p>
+ */
+ private ExecutorService receiveExecutor;
+
+ private IProtocolProvider protocolProvider;
+
+ private INegotiator negotiator;
+
+ public TransportConfig()
+ {
+ }
+
+ public TransportConfig(ILifecycle lifecycle)
+ {
+ this.lifecycle = lifecycle;
+ }
+
+ public TransportConfig(ILifecycle lifecycle, ExecutorService receiveExecutor, IBufferProvider bufferProvider,
+ IProtocolProvider protocolProvider, INegotiator negotiator)
+ {
+ this(lifecycle);
+ this.receiveExecutor = receiveExecutor;
+ this.bufferProvider = bufferProvider;
+ this.protocolProvider = protocolProvider;
+ this.negotiator = negotiator;
+ }
+
+ public ILifecycle getLifecycle()
+ {
+ return lifecycle;
+ }
+
+ public void setLifecycle(ILifecycle lifecycle)
+ {
+ this.lifecycle = lifecycle;
+ }
+
+ public ExecutorService getReceiveExecutor()
+ {
+ return receiveExecutor;
+ }
+
+ public void setReceiveExecutor(ExecutorService receiveExecutor)
+ {
+ LifecycleUtil.checkInactive(lifecycle);
+ this.receiveExecutor = receiveExecutor;
+ }
+
+ public IBufferProvider getBufferProvider()
+ {
+ return bufferProvider;
+ }
+
+ public void setBufferProvider(IBufferProvider bufferProvider)
+ {
+ LifecycleUtil.checkInactive(lifecycle);
+ this.bufferProvider = bufferProvider;
+ }
+
+ public IProtocolProvider getProtocolProvider()
+ {
+ return protocolProvider;
+ }
+
+ public void setProtocolProvider(IProtocolProvider protocolProvider)
+ {
+ LifecycleUtil.checkInactive(lifecycle);
+ this.protocolProvider = protocolProvider;
+ }
+
+ public INegotiator getNegotiator()
+ {
+ return negotiator;
+ }
+
+ public void setNegotiator(INegotiator negotiator)
+ {
+ LifecycleUtil.checkInactive(lifecycle);
+ this.negotiator = negotiator;
+ }
+
+ @Override
+ public String toString()
+ {
+ return MessageFormat.format(
+ "TransportConfig[receiveExecutor={0}, bufferProvider={1}, protocolProvider={2}, negotiator={3}]", //$NON-NLS-1$
+ receiveExecutor, bufferProvider, protocolProvider, negotiator);
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/Buffer.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/Buffer.java
index d8a30547f5..69123bc6fe 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/Buffer.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/Buffer.java
@@ -1,432 +1,432 @@
-/*
- * 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.internal.net4j.buffer;
-
-import org.eclipse.net4j.buffer.BufferState;
-import org.eclipse.net4j.buffer.IBuffer;
-import org.eclipse.net4j.buffer.IBufferProvider;
-import org.eclipse.net4j.util.HexUtil;
-import org.eclipse.net4j.util.IErrorHandler;
-import org.eclipse.net4j.util.ReflectUtil;
-import org.eclipse.net4j.util.StringUtil;
-import org.eclipse.net4j.util.om.trace.ContextTracer;
-
-import org.eclipse.internal.net4j.bundle.OM;
-
-import org.eclipse.spi.net4j.InternalBuffer;
-
-import java.io.IOException;
-import java.nio.ByteBuffer;
-import java.nio.channels.ClosedChannelException;
-import java.nio.channels.SocketChannel;
-import java.text.MessageFormat;
-
-/**
- * @author Eike Stepper
- * @since 4.0
- */
-public class Buffer implements InternalBuffer
-{
- public static final int EOS_OFFSET = 1;
-
- private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_BUFFER, Buffer.class);
-
- private IErrorHandler errorHandler;
-
- private IBufferProvider bufferProvider;
-
- private short channelID;
-
- private boolean eos;
-
- private BufferState state = BufferState.INITIAL;
-
- private ByteBuffer byteBuffer;
-
- public Buffer(IBufferProvider provider, short capacity)
- {
- bufferProvider = provider;
- byteBuffer = ByteBuffer.allocateDirect(capacity);
- }
-
- public boolean isEOS()
- {
- return eos;
- }
-
- public void setEOS(boolean eos)
- {
- this.eos = eos;
- }
-
- public IBufferProvider getBufferProvider()
- {
- return bufferProvider;
- }
-
- public void setBufferProvider(IBufferProvider bufferProvider)
- {
- this.bufferProvider = bufferProvider;
- }
-
- public short getChannelID()
- {
- if (state == BufferState.INITIAL || state == BufferState.READING_HEADER)
- {
- throw new IllegalStateException(toString());
- }
-
- return channelID;
- }
-
- public void setChannelID(short channelID)
- {
- this.channelID = channelID;
- }
-
- public short getCapacity()
- {
- return (short)byteBuffer.capacity();
- }
-
- public BufferState getState()
- {
- return state;
- }
-
- public void setState(BufferState state)
- {
- this.state = state;
- }
-
- public ByteBuffer getByteBuffer()
- {
- return byteBuffer;
- }
-
- public void setByteBuffer(ByteBuffer buffer)
- {
- byteBuffer = buffer;
- }
-
- public void clear()
- {
- state = BufferState.INITIAL;
- channelID = NO_CHANNEL;
- eos = false;
- byteBuffer.clear();
- }
-
- public void release()
- {
- if (state != BufferState.RELEASED)
- {
- state = BufferState.RELEASED;
- errorHandler = null;
- if (bufferProvider != null)
- {
- bufferProvider.retainBuffer(this);
- }
- }
- }
-
- public void dispose()
- {
- state = BufferState.DISPOSED;
- bufferProvider = null;
- byteBuffer = null;
- }
-
- public ByteBuffer startGetting(SocketChannel socketChannel) throws IOException
- {
- try
- {
- if (state != BufferState.INITIAL && state != BufferState.READING_HEADER && state != BufferState.READING_BODY)
- {
- throw new IllegalStateException(toString());
- }
-
- if (state == BufferState.INITIAL)
- {
- byteBuffer.limit(IBuffer.HEADER_SIZE);
- state = BufferState.READING_HEADER;
- }
-
- if (state == BufferState.READING_HEADER)
- {
- readChannel(socketChannel, byteBuffer);
- if (byteBuffer.hasRemaining())
- {
- return null;
- }
-
- byteBuffer.flip();
- channelID = byteBuffer.getShort();
- short payloadSize = byteBuffer.getShort();
- if (payloadSize < 0)
- {
- eos = true;
- payloadSize = (short)-payloadSize;
- }
-
- payloadSize -= EOS_OFFSET;
-
- byteBuffer.clear();
- byteBuffer.limit(payloadSize);
- state = BufferState.READING_BODY;
- }
-
- readChannel(socketChannel, byteBuffer);
- if (byteBuffer.hasRemaining())
- {
- return null;
- }
-
- if (TRACER.isEnabled())
- {
- TRACER.trace("Read " + byteBuffer.limit() + " bytes" //$NON-NLS-1$ //$NON-NLS-2$
- + (eos ? " (EOS)" : "") + StringUtil.NL + formatContent(false)); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- byteBuffer.flip();
- state = BufferState.GETTING;
- return byteBuffer;
- }
- catch (IOException ex)
- {
- handleError(ex);
- throw ex;
- }
- catch (RuntimeException ex)
- {
- handleError(ex);
- throw ex;
- }
- catch (Error ex)
- {
- handleError(ex);
- throw ex;
- }
- }
-
- public ByteBuffer startPutting(short channelID)
- {
- try
- {
- if (state == BufferState.PUTTING)
- {
- if (channelID != this.channelID)
- {
- throw new IllegalArgumentException("channelID != this.channelID"); //$NON-NLS-1$
- }
- }
- else if (state != BufferState.INITIAL)
- {
- throw new IllegalStateException("state: " + state); //$NON-NLS-1$
- }
- else
- {
- state = BufferState.PUTTING;
- this.channelID = channelID;
-
- byteBuffer.clear();
- byteBuffer.position(IBuffer.HEADER_SIZE);
- }
-
- return byteBuffer;
- }
- catch (RuntimeException ex)
- {
- handleError(ex);
- throw ex;
- }
- catch (Error ex)
- {
- handleError(ex);
- throw ex;
- }
- }
-
- /**
- * @return <code>true</code> if the buffer has been completely written, <code>false</code> otherwise.
- */
- public boolean write(SocketChannel socketChannel) throws IOException
- {
- try
- {
- if (state != BufferState.PUTTING && state != BufferState.WRITING)
- {
- throw new IllegalStateException(toString());
- }
-
- if (state == BufferState.PUTTING)
- {
- if (channelID == NO_CHANNEL)
- {
- throw new IllegalStateException("channelID == NO_CHANNEL"); //$NON-NLS-1$
- }
-
- int payloadSize = byteBuffer.position() - IBuffer.HEADER_SIZE + EOS_OFFSET;
- if (eos)
- {
- payloadSize = -payloadSize;
- }
-
- if (TRACER.isEnabled())
- {
- TRACER.trace("Writing " + (Math.abs(payloadSize) - 1) + " bytes" //$NON-NLS-1$ //$NON-NLS-2$
- + (eos ? " (EOS)" : "") + StringUtil.NL + formatContent(false)); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- byteBuffer.flip();
- byteBuffer.putShort(channelID);
- byteBuffer.putShort((short)payloadSize);
- byteBuffer.position(0);
- state = BufferState.WRITING;
- }
-
- int numBytes = socketChannel.write(byteBuffer);
- if (numBytes == -1)
- {
- throw new IOException("Channel closed"); //$NON-NLS-1$
- }
-
- if (byteBuffer.hasRemaining())
- {
- return false;
- }
-
- clear();
- return true;
- }
- catch (IOException ex)
- {
- handleError(ex);
- throw ex;
- }
- catch (RuntimeException ex)
- {
- handleError(ex);
- throw ex;
- }
- catch (Error ex)
- {
- handleError(ex);
- throw ex;
- }
- }
-
- public void flip()
- {
- try
- {
- if (state != BufferState.PUTTING)
- {
- throw new IllegalStateException(toString());
- }
-
- byteBuffer.flip();
- byteBuffer.position(IBuffer.HEADER_SIZE);
- state = BufferState.GETTING;
- }
- catch (RuntimeException ex)
- {
- handleError(ex);
- throw ex;
- }
- catch (Error ex)
- {
- handleError(ex);
- throw ex;
- }
- }
-
- @Override
- public String toString()
- {
- return MessageFormat.format("Buffer@{0}[{1}]", ReflectUtil.getID(this), state); //$NON-NLS-1$
- }
-
- @SuppressWarnings("deprecation")
- public String formatContent(boolean showHeader)
- {
- final int oldPosition = byteBuffer.position();
- final int oldLimit = byteBuffer.limit();
-
- try
- {
- if (state != BufferState.GETTING)
- {
- byteBuffer.flip();
- }
-
- if (state == BufferState.PUTTING && !showHeader)
- {
- byteBuffer.position(IBuffer.HEADER_SIZE);
- }
-
- StringBuilder builder = new StringBuilder();
- while (byteBuffer.hasRemaining())
- {
- byte b = byteBuffer.get();
- HexUtil.appendHex(builder, b < 0 ? ~b : b);
- builder.append(' ');
- }
-
- return builder.toString();
- }
- finally
- {
- byteBuffer.position(oldPosition);
- byteBuffer.limit(oldLimit);
- }
- }
-
- public IErrorHandler getErrorHandler()
- {
- return errorHandler;
- }
-
- public void setErrorHandler(IErrorHandler errorHandler)
- {
- this.errorHandler = errorHandler;
- }
-
- public void handleError(Throwable t)
- {
- if (errorHandler != null)
- {
- errorHandler.handleError(t);
- }
-
- release();
- }
-
- private static void readChannel(SocketChannel socketChannel, ByteBuffer buffer) throws ClosedChannelException
- {
- try
- {
- if (socketChannel.read(buffer) == -1)
- {
- throw new ClosedChannelException();
- }
- }
- catch (ClosedChannelException ex)
- {
- throw ex;
- }
- catch (IOException ex)
- {
- throw new ClosedChannelException();
- }
- }
-}
+/*
+ * 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.internal.net4j.buffer;
+
+import org.eclipse.net4j.buffer.BufferState;
+import org.eclipse.net4j.buffer.IBuffer;
+import org.eclipse.net4j.buffer.IBufferProvider;
+import org.eclipse.net4j.util.HexUtil;
+import org.eclipse.net4j.util.IErrorHandler;
+import org.eclipse.net4j.util.ReflectUtil;
+import org.eclipse.net4j.util.StringUtil;
+import org.eclipse.net4j.util.om.trace.ContextTracer;
+
+import org.eclipse.internal.net4j.bundle.OM;
+
+import org.eclipse.spi.net4j.InternalBuffer;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.channels.ClosedChannelException;
+import java.nio.channels.SocketChannel;
+import java.text.MessageFormat;
+
+/**
+ * @author Eike Stepper
+ * @since 4.0
+ */
+public class Buffer implements InternalBuffer
+{
+ public static final int EOS_OFFSET = 1;
+
+ private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_BUFFER, Buffer.class);
+
+ private IErrorHandler errorHandler;
+
+ private IBufferProvider bufferProvider;
+
+ private short channelID;
+
+ private boolean eos;
+
+ private BufferState state = BufferState.INITIAL;
+
+ private ByteBuffer byteBuffer;
+
+ public Buffer(IBufferProvider provider, short capacity)
+ {
+ bufferProvider = provider;
+ byteBuffer = ByteBuffer.allocateDirect(capacity);
+ }
+
+ public boolean isEOS()
+ {
+ return eos;
+ }
+
+ public void setEOS(boolean eos)
+ {
+ this.eos = eos;
+ }
+
+ public IBufferProvider getBufferProvider()
+ {
+ return bufferProvider;
+ }
+
+ public void setBufferProvider(IBufferProvider bufferProvider)
+ {
+ this.bufferProvider = bufferProvider;
+ }
+
+ public short getChannelID()
+ {
+ if (state == BufferState.INITIAL || state == BufferState.READING_HEADER)
+ {
+ throw new IllegalStateException(toString());
+ }
+
+ return channelID;
+ }
+
+ public void setChannelID(short channelID)
+ {
+ this.channelID = channelID;
+ }
+
+ public short getCapacity()
+ {
+ return (short)byteBuffer.capacity();
+ }
+
+ public BufferState getState()
+ {
+ return state;
+ }
+
+ public void setState(BufferState state)
+ {
+ this.state = state;
+ }
+
+ public ByteBuffer getByteBuffer()
+ {
+ return byteBuffer;
+ }
+
+ public void setByteBuffer(ByteBuffer buffer)
+ {
+ byteBuffer = buffer;
+ }
+
+ public void clear()
+ {
+ state = BufferState.INITIAL;
+ channelID = NO_CHANNEL;
+ eos = false;
+ byteBuffer.clear();
+ }
+
+ public void release()
+ {
+ if (state != BufferState.RELEASED)
+ {
+ state = BufferState.RELEASED;
+ errorHandler = null;
+ if (bufferProvider != null)
+ {
+ bufferProvider.retainBuffer(this);
+ }
+ }
+ }
+
+ public void dispose()
+ {
+ state = BufferState.DISPOSED;
+ bufferProvider = null;
+ byteBuffer = null;
+ }
+
+ public ByteBuffer startGetting(SocketChannel socketChannel) throws IOException
+ {
+ try
+ {
+ if (state != BufferState.INITIAL && state != BufferState.READING_HEADER && state != BufferState.READING_BODY)
+ {
+ throw new IllegalStateException(toString());
+ }
+
+ if (state == BufferState.INITIAL)
+ {
+ byteBuffer.limit(IBuffer.HEADER_SIZE);
+ state = BufferState.READING_HEADER;
+ }
+
+ if (state == BufferState.READING_HEADER)
+ {
+ readChannel(socketChannel, byteBuffer);
+ if (byteBuffer.hasRemaining())
+ {
+ return null;
+ }
+
+ byteBuffer.flip();
+ channelID = byteBuffer.getShort();
+ short payloadSize = byteBuffer.getShort();
+ if (payloadSize < 0)
+ {
+ eos = true;
+ payloadSize = (short)-payloadSize;
+ }
+
+ payloadSize -= EOS_OFFSET;
+
+ byteBuffer.clear();
+ byteBuffer.limit(payloadSize);
+ state = BufferState.READING_BODY;
+ }
+
+ readChannel(socketChannel, byteBuffer);
+ if (byteBuffer.hasRemaining())
+ {
+ return null;
+ }
+
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace("Read " + byteBuffer.limit() + " bytes" //$NON-NLS-1$ //$NON-NLS-2$
+ + (eos ? " (EOS)" : "") + StringUtil.NL + formatContent(false)); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ byteBuffer.flip();
+ state = BufferState.GETTING;
+ return byteBuffer;
+ }
+ catch (IOException ex)
+ {
+ handleError(ex);
+ throw ex;
+ }
+ catch (RuntimeException ex)
+ {
+ handleError(ex);
+ throw ex;
+ }
+ catch (Error ex)
+ {
+ handleError(ex);
+ throw ex;
+ }
+ }
+
+ public ByteBuffer startPutting(short channelID)
+ {
+ try
+ {
+ if (state == BufferState.PUTTING)
+ {
+ if (channelID != this.channelID)
+ {
+ throw new IllegalArgumentException("channelID != this.channelID"); //$NON-NLS-1$
+ }
+ }
+ else if (state != BufferState.INITIAL)
+ {
+ throw new IllegalStateException("state: " + state); //$NON-NLS-1$
+ }
+ else
+ {
+ state = BufferState.PUTTING;
+ this.channelID = channelID;
+
+ byteBuffer.clear();
+ byteBuffer.position(IBuffer.HEADER_SIZE);
+ }
+
+ return byteBuffer;
+ }
+ catch (RuntimeException ex)
+ {
+ handleError(ex);
+ throw ex;
+ }
+ catch (Error ex)
+ {
+ handleError(ex);
+ throw ex;
+ }
+ }
+
+ /**
+ * @return <code>true</code> if the buffer has been completely written, <code>false</code> otherwise.
+ */
+ public boolean write(SocketChannel socketChannel) throws IOException
+ {
+ try
+ {
+ if (state != BufferState.PUTTING && state != BufferState.WRITING)
+ {
+ throw new IllegalStateException(toString());
+ }
+
+ if (state == BufferState.PUTTING)
+ {
+ if (channelID == NO_CHANNEL)
+ {
+ throw new IllegalStateException("channelID == NO_CHANNEL"); //$NON-NLS-1$
+ }
+
+ int payloadSize = byteBuffer.position() - IBuffer.HEADER_SIZE + EOS_OFFSET;
+ if (eos)
+ {
+ payloadSize = -payloadSize;
+ }
+
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace("Writing " + (Math.abs(payloadSize) - 1) + " bytes" //$NON-NLS-1$ //$NON-NLS-2$
+ + (eos ? " (EOS)" : "") + StringUtil.NL + formatContent(false)); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ byteBuffer.flip();
+ byteBuffer.putShort(channelID);
+ byteBuffer.putShort((short)payloadSize);
+ byteBuffer.position(0);
+ state = BufferState.WRITING;
+ }
+
+ int numBytes = socketChannel.write(byteBuffer);
+ if (numBytes == -1)
+ {
+ throw new IOException("Channel closed"); //$NON-NLS-1$
+ }
+
+ if (byteBuffer.hasRemaining())
+ {
+ return false;
+ }
+
+ clear();
+ return true;
+ }
+ catch (IOException ex)
+ {
+ handleError(ex);
+ throw ex;
+ }
+ catch (RuntimeException ex)
+ {
+ handleError(ex);
+ throw ex;
+ }
+ catch (Error ex)
+ {
+ handleError(ex);
+ throw ex;
+ }
+ }
+
+ public void flip()
+ {
+ try
+ {
+ if (state != BufferState.PUTTING)
+ {
+ throw new IllegalStateException(toString());
+ }
+
+ byteBuffer.flip();
+ byteBuffer.position(IBuffer.HEADER_SIZE);
+ state = BufferState.GETTING;
+ }
+ catch (RuntimeException ex)
+ {
+ handleError(ex);
+ throw ex;
+ }
+ catch (Error ex)
+ {
+ handleError(ex);
+ throw ex;
+ }
+ }
+
+ @Override
+ public String toString()
+ {
+ return MessageFormat.format("Buffer@{0}[{1}]", ReflectUtil.getID(this), state); //$NON-NLS-1$
+ }
+
+ @SuppressWarnings("deprecation")
+ public String formatContent(boolean showHeader)
+ {
+ final int oldPosition = byteBuffer.position();
+ final int oldLimit = byteBuffer.limit();
+
+ try
+ {
+ if (state != BufferState.GETTING)
+ {
+ byteBuffer.flip();
+ }
+
+ if (state == BufferState.PUTTING && !showHeader)
+ {
+ byteBuffer.position(IBuffer.HEADER_SIZE);
+ }
+
+ StringBuilder builder = new StringBuilder();
+ while (byteBuffer.hasRemaining())
+ {
+ byte b = byteBuffer.get();
+ HexUtil.appendHex(builder, b < 0 ? ~b : b);
+ builder.append(' ');
+ }
+
+ return builder.toString();
+ }
+ finally
+ {
+ byteBuffer.position(oldPosition);
+ byteBuffer.limit(oldLimit);
+ }
+ }
+
+ public IErrorHandler getErrorHandler()
+ {
+ return errorHandler;
+ }
+
+ public void setErrorHandler(IErrorHandler errorHandler)
+ {
+ this.errorHandler = errorHandler;
+ }
+
+ public void handleError(Throwable t)
+ {
+ if (errorHandler != null)
+ {
+ errorHandler.handleError(t);
+ }
+
+ release();
+ }
+
+ private static void readChannel(SocketChannel socketChannel, ByteBuffer buffer) throws ClosedChannelException
+ {
+ try
+ {
+ if (socketChannel.read(buffer) == -1)
+ {
+ throw new ClosedChannelException();
+ }
+ }
+ catch (ClosedChannelException ex)
+ {
+ throw ex;
+ }
+ catch (IOException ex)
+ {
+ throw new ClosedChannelException();
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/BufferFactory.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/BufferFactory.java
index 2dd3a1ccf1..6d6ead780a 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/BufferFactory.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/BufferFactory.java
@@ -1,62 +1,62 @@
-/*
- * 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.internal.net4j.buffer;
-
-import org.eclipse.net4j.buffer.IBuffer;
-import org.eclipse.net4j.util.om.trace.ContextTracer;
-
-import org.eclipse.internal.net4j.bundle.OM;
-
-import org.eclipse.spi.net4j.InternalBuffer;
-
-import java.text.MessageFormat;
-
-/**
- * @author Eike Stepper
- */
-public class BufferFactory extends BufferProvider
-{
- private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_BUFFER, BufferFactory.class);
-
- public BufferFactory(short bufferCapacity)
- {
- super(bufferCapacity);
- }
-
- @Override
- protected IBuffer doProvideBuffer()
- {
- IBuffer buffer = new Buffer(this, getBufferCapacity());
- if (TRACER.isEnabled())
- {
- TRACER.trace("Created " + buffer); //$NON-NLS-1$
- }
-
- return buffer;
- }
-
- @Override
- protected void doRetainBuffer(IBuffer buffer)
- {
- if (buffer instanceof InternalBuffer)
- {
- ((InternalBuffer)buffer).dispose();
- }
-
- buffer = null;
- }
-
- @Override
- public String toString()
- {
- return MessageFormat.format("BufferFactory[{0}]", getBufferCapacity()); //$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.internal.net4j.buffer;
+
+import org.eclipse.net4j.buffer.IBuffer;
+import org.eclipse.net4j.util.om.trace.ContextTracer;
+
+import org.eclipse.internal.net4j.bundle.OM;
+
+import org.eclipse.spi.net4j.InternalBuffer;
+
+import java.text.MessageFormat;
+
+/**
+ * @author Eike Stepper
+ */
+public class BufferFactory extends BufferProvider
+{
+ private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_BUFFER, BufferFactory.class);
+
+ public BufferFactory(short bufferCapacity)
+ {
+ super(bufferCapacity);
+ }
+
+ @Override
+ protected IBuffer doProvideBuffer()
+ {
+ IBuffer buffer = new Buffer(this, getBufferCapacity());
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace("Created " + buffer); //$NON-NLS-1$
+ }
+
+ return buffer;
+ }
+
+ @Override
+ protected void doRetainBuffer(IBuffer buffer)
+ {
+ if (buffer instanceof InternalBuffer)
+ {
+ ((InternalBuffer)buffer).dispose();
+ }
+
+ buffer = null;
+ }
+
+ @Override
+ public String toString()
+ {
+ return MessageFormat.format("BufferFactory[{0}]", getBufferCapacity()); //$NON-NLS-1$
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/BufferPool.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/BufferPool.java
index 530be39c26..26d0fd85ae 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/BufferPool.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/BufferPool.java
@@ -1,243 +1,243 @@
-/*
- * 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.internal.net4j.buffer;
-
-import org.eclipse.net4j.buffer.IBuffer;
-import org.eclipse.net4j.buffer.IBufferPool;
-import org.eclipse.net4j.buffer.IBufferProvider;
-import org.eclipse.net4j.util.ReflectUtil.ExcludeFromDump;
-import org.eclipse.net4j.util.om.trace.ContextTracer;
-
-import org.eclipse.internal.net4j.bundle.OM;
-
-import org.eclipse.spi.net4j.InternalBuffer;
-
-import java.lang.ref.Reference;
-import java.lang.ref.ReferenceQueue;
-import java.lang.ref.SoftReference;
-import java.text.MessageFormat;
-import java.util.Queue;
-import java.util.concurrent.ConcurrentLinkedQueue;
-
-/**
- * @author Eike Stepper
- */
-public class BufferPool extends BufferProvider implements IBufferPool.Introspection
-{
- private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_BUFFER, BufferPool.class);
-
- private final IBufferProvider provider;
-
- private int pooledBuffers;
-
- @ExcludeFromDump
- private final Queue<BufferRef> buffers = new ConcurrentLinkedQueue<BufferRef>();
-
- @ExcludeFromDump
- private final ReferenceQueue<IBuffer> referenceQueue = new ReferenceQueue<IBuffer>();
-
- @ExcludeFromDump
- private Monitor monitor;
-
- public BufferPool(IBufferProvider provider)
- {
- super(provider.getBufferCapacity());
- this.provider = provider;
- }
-
- public IBufferProvider getProvider()
- {
- return provider;
- }
-
- public ReferenceQueue<IBuffer> getReferenceQueue()
- {
- return referenceQueue;
- }
-
- public int getPooledBuffers()
- {
- return pooledBuffers;
- }
-
- public boolean evictOne()
- {
- for (;;)
- {
- BufferRef bufferRef = buffers.poll();
- if (bufferRef == null)
- {
- return false;
- }
-
- IBuffer buffer = bufferRef.get();
- if (buffer != null)
- {
- if (TRACER.isEnabled())
- {
- TRACER.trace("Evicting " + buffer); //$NON-NLS-1$
- }
-
- provider.retainBuffer(buffer);
- --pooledBuffers;
- return true;
- }
- }
- }
-
- public int evict(int survivors)
- {
- int evictedBuffers = 0;
- while (pooledBuffers > survivors)
- {
- if (evictOne())
- {
- ++evictedBuffers;
- }
- else
- {
- break;
- }
- }
-
- return evictedBuffers;
- }
-
- @Override
- public String toString()
- {
- return MessageFormat.format("BufferPool[{0}]", getBufferCapacity()); //$NON-NLS-1$
- }
-
- protected BufferRef createBufferRef(IBuffer buffer)
- {
- return new BufferRef(buffer, referenceQueue);
- }
-
- @Override
- protected IBuffer doProvideBuffer()
- {
- IBuffer buffer = null;
- BufferRef bufferRef = buffers.poll();
- if (bufferRef != null)
- {
- buffer = bufferRef.get();
- }
-
- if (buffer == null)
- {
- buffer = provider.provideBuffer();
- ((InternalBuffer)buffer).setBufferProvider(this);
- }
- else
- {
- --pooledBuffers;
- }
-
- buffer.clear();
- if (TRACER.isEnabled())
- {
- TRACER.trace("Obtained " + buffer); //$NON-NLS-1$
- }
-
- return buffer;
- }
-
- @Override
- protected void doRetainBuffer(IBuffer buffer)
- {
- if (buffer.getCapacity() != getBufferCapacity())
- {
- throw new IllegalArgumentException("buffer.getCapacity() != getBufferCapacity()"); //$NON-NLS-1$
- }
-
- if (TRACER.isEnabled())
- {
- TRACER.trace("Retaining " + buffer); //$NON-NLS-1$
- }
-
- BufferRef bufferRef = createBufferRef(buffer);
- buffers.add(bufferRef);
- ++pooledBuffers;
- }
-
- @Override
- protected void doActivate() throws Exception
- {
- super.doActivate();
- monitor = new Monitor();
- monitor.start();
- }
-
- @Override
- protected void doDeactivate() throws Exception
- {
- monitor.interrupt();
- monitor = null;
- super.doDeactivate();
- }
-
- private static final class BufferRef extends SoftReference<IBuffer>
- {
- public BufferRef(IBuffer buffer, ReferenceQueue<IBuffer> queue)
- {
- super(buffer, queue);
- }
- }
-
- private final class Monitor extends Thread
- {
- public Monitor()
- {
- setName("BufferPoolMonitor"); //$NON-NLS-1$
- setDaemon(true);
- }
-
- @Override
- public void run()
- {
- if (TRACER.isEnabled())
- {
- TRACER.trace("Start monitoring"); //$NON-NLS-1$
- }
-
- try
- {
- while (isActive() && !isInterrupted())
- {
- Reference<? extends IBuffer> bufferRef = referenceQueue.remove(200);
- if (bufferRef != null)
- {
- if (buffers.remove(bufferRef))
- {
- --pooledBuffers;
- if (TRACER.isEnabled())
- {
- TRACER.trace("Collected buffer"); //$NON-NLS-1$
- }
- }
- }
- }
- }
- catch (InterruptedException ex)
- {
- return;
- }
- finally
- {
- if (TRACER.isEnabled())
- {
- TRACER.trace("Stop monitoring"); //$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.internal.net4j.buffer;
+
+import org.eclipse.net4j.buffer.IBuffer;
+import org.eclipse.net4j.buffer.IBufferPool;
+import org.eclipse.net4j.buffer.IBufferProvider;
+import org.eclipse.net4j.util.ReflectUtil.ExcludeFromDump;
+import org.eclipse.net4j.util.om.trace.ContextTracer;
+
+import org.eclipse.internal.net4j.bundle.OM;
+
+import org.eclipse.spi.net4j.InternalBuffer;
+
+import java.lang.ref.Reference;
+import java.lang.ref.ReferenceQueue;
+import java.lang.ref.SoftReference;
+import java.text.MessageFormat;
+import java.util.Queue;
+import java.util.concurrent.ConcurrentLinkedQueue;
+
+/**
+ * @author Eike Stepper
+ */
+public class BufferPool extends BufferProvider implements IBufferPool.Introspection
+{
+ private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_BUFFER, BufferPool.class);
+
+ private final IBufferProvider provider;
+
+ private int pooledBuffers;
+
+ @ExcludeFromDump
+ private final Queue<BufferRef> buffers = new ConcurrentLinkedQueue<BufferRef>();
+
+ @ExcludeFromDump
+ private final ReferenceQueue<IBuffer> referenceQueue = new ReferenceQueue<IBuffer>();
+
+ @ExcludeFromDump
+ private Monitor monitor;
+
+ public BufferPool(IBufferProvider provider)
+ {
+ super(provider.getBufferCapacity());
+ this.provider = provider;
+ }
+
+ public IBufferProvider getProvider()
+ {
+ return provider;
+ }
+
+ public ReferenceQueue<IBuffer> getReferenceQueue()
+ {
+ return referenceQueue;
+ }
+
+ public int getPooledBuffers()
+ {
+ return pooledBuffers;
+ }
+
+ public boolean evictOne()
+ {
+ for (;;)
+ {
+ BufferRef bufferRef = buffers.poll();
+ if (bufferRef == null)
+ {
+ return false;
+ }
+
+ IBuffer buffer = bufferRef.get();
+ if (buffer != null)
+ {
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace("Evicting " + buffer); //$NON-NLS-1$
+ }
+
+ provider.retainBuffer(buffer);
+ --pooledBuffers;
+ return true;
+ }
+ }
+ }
+
+ public int evict(int survivors)
+ {
+ int evictedBuffers = 0;
+ while (pooledBuffers > survivors)
+ {
+ if (evictOne())
+ {
+ ++evictedBuffers;
+ }
+ else
+ {
+ break;
+ }
+ }
+
+ return evictedBuffers;
+ }
+
+ @Override
+ public String toString()
+ {
+ return MessageFormat.format("BufferPool[{0}]", getBufferCapacity()); //$NON-NLS-1$
+ }
+
+ protected BufferRef createBufferRef(IBuffer buffer)
+ {
+ return new BufferRef(buffer, referenceQueue);
+ }
+
+ @Override
+ protected IBuffer doProvideBuffer()
+ {
+ IBuffer buffer = null;
+ BufferRef bufferRef = buffers.poll();
+ if (bufferRef != null)
+ {
+ buffer = bufferRef.get();
+ }
+
+ if (buffer == null)
+ {
+ buffer = provider.provideBuffer();
+ ((InternalBuffer)buffer).setBufferProvider(this);
+ }
+ else
+ {
+ --pooledBuffers;
+ }
+
+ buffer.clear();
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace("Obtained " + buffer); //$NON-NLS-1$
+ }
+
+ return buffer;
+ }
+
+ @Override
+ protected void doRetainBuffer(IBuffer buffer)
+ {
+ if (buffer.getCapacity() != getBufferCapacity())
+ {
+ throw new IllegalArgumentException("buffer.getCapacity() != getBufferCapacity()"); //$NON-NLS-1$
+ }
+
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace("Retaining " + buffer); //$NON-NLS-1$
+ }
+
+ BufferRef bufferRef = createBufferRef(buffer);
+ buffers.add(bufferRef);
+ ++pooledBuffers;
+ }
+
+ @Override
+ protected void doActivate() throws Exception
+ {
+ super.doActivate();
+ monitor = new Monitor();
+ monitor.start();
+ }
+
+ @Override
+ protected void doDeactivate() throws Exception
+ {
+ monitor.interrupt();
+ monitor = null;
+ super.doDeactivate();
+ }
+
+ private static final class BufferRef extends SoftReference<IBuffer>
+ {
+ public BufferRef(IBuffer buffer, ReferenceQueue<IBuffer> queue)
+ {
+ super(buffer, queue);
+ }
+ }
+
+ private final class Monitor extends Thread
+ {
+ public Monitor()
+ {
+ setName("BufferPoolMonitor"); //$NON-NLS-1$
+ setDaemon(true);
+ }
+
+ @Override
+ public void run()
+ {
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace("Start monitoring"); //$NON-NLS-1$
+ }
+
+ try
+ {
+ while (isActive() && !isInterrupted())
+ {
+ Reference<? extends IBuffer> bufferRef = referenceQueue.remove(200);
+ if (bufferRef != null)
+ {
+ if (buffers.remove(bufferRef))
+ {
+ --pooledBuffers;
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace("Collected buffer"); //$NON-NLS-1$
+ }
+ }
+ }
+ }
+ }
+ catch (InterruptedException ex)
+ {
+ return;
+ }
+ finally
+ {
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace("Stop monitoring"); //$NON-NLS-1$
+ }
+ }
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/BufferProvider.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/BufferProvider.java
index 83bcc0764a..796b93f6d3 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/BufferProvider.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/BufferProvider.java
@@ -1,69 +1,69 @@
-/*
- * 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.internal.net4j.buffer;
-
-import org.eclipse.net4j.buffer.IBuffer;
-import org.eclipse.net4j.buffer.IBufferProvider;
-import org.eclipse.net4j.util.lifecycle.Lifecycle;
-
-/**
- * @author Eike Stepper
- */
-public abstract class BufferProvider extends Lifecycle implements IBufferProvider.Introspection
-{
- private short bufferCapacity;
-
- private long providedBuffers;
-
- private long retainedBuffers;
-
- public BufferProvider(short bufferCapacity)
- {
- this.bufferCapacity = bufferCapacity;
- }
-
- public final long getProvidedBuffers()
- {
- return providedBuffers;
- }
-
- public final long getRetainedBuffers()
- {
- return retainedBuffers;
- }
-
- public final short getBufferCapacity()
- {
- return bufferCapacity;
- }
-
- public final IBuffer provideBuffer()
- {
- ++providedBuffers;
- return doProvideBuffer();
- }
-
- public final void retainBuffer(IBuffer buffer)
- {
- ++retainedBuffers;
- doRetainBuffer(buffer);
- }
-
- @Override
- public String toString()
- {
- return "BufferProvider[capacity=" + bufferCapacity + "]"; //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- protected abstract IBuffer doProvideBuffer();
-
- protected abstract void doRetainBuffer(IBuffer 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.internal.net4j.buffer;
+
+import org.eclipse.net4j.buffer.IBuffer;
+import org.eclipse.net4j.buffer.IBufferProvider;
+import org.eclipse.net4j.util.lifecycle.Lifecycle;
+
+/**
+ * @author Eike Stepper
+ */
+public abstract class BufferProvider extends Lifecycle implements IBufferProvider.Introspection
+{
+ private short bufferCapacity;
+
+ private long providedBuffers;
+
+ private long retainedBuffers;
+
+ public BufferProvider(short bufferCapacity)
+ {
+ this.bufferCapacity = bufferCapacity;
+ }
+
+ public final long getProvidedBuffers()
+ {
+ return providedBuffers;
+ }
+
+ public final long getRetainedBuffers()
+ {
+ return retainedBuffers;
+ }
+
+ public final short getBufferCapacity()
+ {
+ return bufferCapacity;
+ }
+
+ public final IBuffer provideBuffer()
+ {
+ ++providedBuffers;
+ return doProvideBuffer();
+ }
+
+ public final void retainBuffer(IBuffer buffer)
+ {
+ ++retainedBuffers;
+ doRetainBuffer(buffer);
+ }
+
+ @Override
+ public String toString()
+ {
+ return "BufferProvider[capacity=" + bufferCapacity + "]"; //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ protected abstract IBuffer doProvideBuffer();
+
+ protected abstract void doRetainBuffer(IBuffer buffer);
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/BufferProviderFactory.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/BufferProviderFactory.java
index 53f203a435..359daef646 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/BufferProviderFactory.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/BufferProviderFactory.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.internal.net4j.buffer;
-
-import org.eclipse.net4j.Net4jUtil;
-import org.eclipse.net4j.buffer.IBufferProvider;
-import org.eclipse.net4j.util.container.IManagedContainer;
-import org.eclipse.net4j.util.factory.Factory;
-
-/**
- * @author Eike Stepper
- */
-public class BufferProviderFactory extends Factory
-{
- public static final String PRODUCT_GROUP = "org.eclipse.net4j.bufferProviders"; //$NON-NLS-1$
-
- public static final String TYPE = "default"; //$NON-NLS-1$
-
- public static final short BUFFER_CAPACITY = 4096;
-
- public BufferProviderFactory()
- {
- super(PRODUCT_GROUP, TYPE);
- }
-
- public IBufferProvider create(String description)
- {
- return Net4jUtil.createBufferPool(BUFFER_CAPACITY);
- }
-
- public static IBufferProvider get(IManagedContainer container)
- {
- return (IBufferProvider)container.getElement(PRODUCT_GROUP, TYPE, null);
- }
-}
+/*
+ * 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.internal.net4j.buffer;
+
+import org.eclipse.net4j.Net4jUtil;
+import org.eclipse.net4j.buffer.IBufferProvider;
+import org.eclipse.net4j.util.container.IManagedContainer;
+import org.eclipse.net4j.util.factory.Factory;
+
+/**
+ * @author Eike Stepper
+ */
+public class BufferProviderFactory extends Factory
+{
+ public static final String PRODUCT_GROUP = "org.eclipse.net4j.bufferProviders"; //$NON-NLS-1$
+
+ public static final String TYPE = "default"; //$NON-NLS-1$
+
+ public static final short BUFFER_CAPACITY = 4096;
+
+ public BufferProviderFactory()
+ {
+ super(PRODUCT_GROUP, TYPE);
+ }
+
+ public IBufferProvider create(String description)
+ {
+ return Net4jUtil.createBufferPool(BUFFER_CAPACITY);
+ }
+
+ public static IBufferProvider get(IManagedContainer container)
+ {
+ return (IBufferProvider)container.getElement(PRODUCT_GROUP, TYPE, null);
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/BufferUtil.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/BufferUtil.java
index 5c7a182192..9d507aeed1 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/BufferUtil.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/buffer/BufferUtil.java
@@ -1,137 +1,137 @@
-/*
- * 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.internal.net4j.buffer;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.UnsupportedEncodingException;
-import java.nio.ByteBuffer;
-
-/**
- * @author Eike Stepper
- */
-public final class BufferUtil
-{
- private static final byte FALSE = (byte)0;
-
- private static final byte TRUE = (byte)1;
-
- public static final String UTF8_CHAR_SET_NAME = "UTF-8"; //$NON-NLS-1$
-
- private BufferUtil()
- {
- }
-
- public static byte[] toUTF8(String str)
- {
- if (str == null)
- {
- return new byte[0];
- }
-
- try
- {
- byte[] bytes = str.getBytes(UTF8_CHAR_SET_NAME);
- String test = new String(bytes, UTF8_CHAR_SET_NAME);
- if (!str.equals(test))
- {
- throw new IllegalArgumentException("String not encodable: " + str); //$NON-NLS-1$
- }
-
- return bytes;
- }
- catch (UnsupportedEncodingException ex)
- {
- // This should really not happen
- throw new RuntimeException(ex);
- }
- }
-
- public static String fromUTF8(byte[] bytes)
- {
- try
- {
- return new String(bytes, UTF8_CHAR_SET_NAME);
- }
- catch (UnsupportedEncodingException ex)
- {
- // This should really not happen
- throw new RuntimeException(ex);
- }
- }
-
- public static void putObject(ByteBuffer byteBuffer, Object object) throws IOException
- {
- if (object != null)
- {
- byteBuffer.put(TRUE);
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ObjectOutputStream stream = new ObjectOutputStream(baos);
- stream.writeObject(object);
-
- byte[] array = baos.toByteArray();
- putByteArray(byteBuffer, array);
- }
- else
- {
- byteBuffer.put(FALSE);
- }
- }
-
- public static Object getObject(ByteBuffer byteBuffer) throws IOException, ClassNotFoundException
- {
- boolean nonNull = byteBuffer.get() == TRUE;
- if (nonNull)
- {
- byte[] array = getByteArray(byteBuffer);
- ByteArrayInputStream bais = new ByteArrayInputStream(array);
- ObjectInputStream stream = new ObjectInputStream(bais);
- return stream.readObject();
- }
-
- return null;
- }
-
- public static void putByteArray(ByteBuffer byteBuffer, byte[] array)
- {
- byteBuffer.putShort((short)array.length);
- if (array.length != 0)
- {
- byteBuffer.put(array);
- }
- }
-
- public static byte[] getByteArray(ByteBuffer byteBuffer)
- {
- short length = byteBuffer.getShort();
- byte[] array = new byte[length];
- if (length != 0)
- {
- byteBuffer.get(array);
- }
-
- return array;
- }
-
- public static void putUTF8(ByteBuffer byteBuffer, String str)
- {
- byte[] bytes = BufferUtil.toUTF8(str);
- if (bytes.length > byteBuffer.remaining())
- {
- throw new IllegalArgumentException("String too long: " + str); //$NON-NLS-1$
- }
-
- putByteArray(byteBuffer, 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.internal.net4j.buffer;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.UnsupportedEncodingException;
+import java.nio.ByteBuffer;
+
+/**
+ * @author Eike Stepper
+ */
+public final class BufferUtil
+{
+ private static final byte FALSE = (byte)0;
+
+ private static final byte TRUE = (byte)1;
+
+ public static final String UTF8_CHAR_SET_NAME = "UTF-8"; //$NON-NLS-1$
+
+ private BufferUtil()
+ {
+ }
+
+ public static byte[] toUTF8(String str)
+ {
+ if (str == null)
+ {
+ return new byte[0];
+ }
+
+ try
+ {
+ byte[] bytes = str.getBytes(UTF8_CHAR_SET_NAME);
+ String test = new String(bytes, UTF8_CHAR_SET_NAME);
+ if (!str.equals(test))
+ {
+ throw new IllegalArgumentException("String not encodable: " + str); //$NON-NLS-1$
+ }
+
+ return bytes;
+ }
+ catch (UnsupportedEncodingException ex)
+ {
+ // This should really not happen
+ throw new RuntimeException(ex);
+ }
+ }
+
+ public static String fromUTF8(byte[] bytes)
+ {
+ try
+ {
+ return new String(bytes, UTF8_CHAR_SET_NAME);
+ }
+ catch (UnsupportedEncodingException ex)
+ {
+ // This should really not happen
+ throw new RuntimeException(ex);
+ }
+ }
+
+ public static void putObject(ByteBuffer byteBuffer, Object object) throws IOException
+ {
+ if (object != null)
+ {
+ byteBuffer.put(TRUE);
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream stream = new ObjectOutputStream(baos);
+ stream.writeObject(object);
+
+ byte[] array = baos.toByteArray();
+ putByteArray(byteBuffer, array);
+ }
+ else
+ {
+ byteBuffer.put(FALSE);
+ }
+ }
+
+ public static Object getObject(ByteBuffer byteBuffer) throws IOException, ClassNotFoundException
+ {
+ boolean nonNull = byteBuffer.get() == TRUE;
+ if (nonNull)
+ {
+ byte[] array = getByteArray(byteBuffer);
+ ByteArrayInputStream bais = new ByteArrayInputStream(array);
+ ObjectInputStream stream = new ObjectInputStream(bais);
+ return stream.readObject();
+ }
+
+ return null;
+ }
+
+ public static void putByteArray(ByteBuffer byteBuffer, byte[] array)
+ {
+ byteBuffer.putShort((short)array.length);
+ if (array.length != 0)
+ {
+ byteBuffer.put(array);
+ }
+ }
+
+ public static byte[] getByteArray(ByteBuffer byteBuffer)
+ {
+ short length = byteBuffer.getShort();
+ byte[] array = new byte[length];
+ if (length != 0)
+ {
+ byteBuffer.get(array);
+ }
+
+ return array;
+ }
+
+ public static void putUTF8(ByteBuffer byteBuffer, String str)
+ {
+ byte[] bytes = BufferUtil.toUTF8(str);
+ if (bytes.length > byteBuffer.remaining())
+ {
+ throw new IllegalArgumentException("String too long: " + str); //$NON-NLS-1$
+ }
+
+ putByteArray(byteBuffer, bytes);
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/Net4jCommandProvider.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/Net4jCommandProvider.java
index 41e2c39ae2..6bc05019bf 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/Net4jCommandProvider.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/Net4jCommandProvider.java
@@ -1,116 +1,116 @@
-/*
- * 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.internal.net4j.bundle;
-
-import org.eclipse.net4j.util.container.IContainer;
-import org.eclipse.net4j.util.container.IPluginContainer;
-
-import org.eclipse.osgi.framework.console.CommandInterpreter;
-import org.eclipse.osgi.framework.console.CommandProvider;
-import org.eclipse.spi.net4j.AcceptorFactory;
-import org.eclipse.spi.net4j.ConnectorFactory;
-
-import org.osgi.framework.BundleContext;
-
-/**
- * @author Eike Stepper
- */
-public class Net4jCommandProvider implements CommandProvider
-{
- public Net4jCommandProvider(BundleContext bundleContext)
- {
- bundleContext.registerService(CommandProvider.class.getName(), this, null);
- }
-
- public String getHelp()
- {
- StringBuffer buffer = new StringBuffer();
- buffer.append("---Net4j commands---\n");
- buffer.append("\telements - list all managed elements\n");
- buffer.append("\tacceptors - list all active acceptors, their connectors and channels\n");
- buffer.append("\tconnectors - list all active connectors and their channels\n");
- return buffer.toString();
- }
-
- public Object _elements(CommandInterpreter interpreter)
- {
- try
- {
- for (String productGroup : getContainer().getProductGroups())
- {
- interpreter.println(productGroup);
- printFactoryTypes(interpreter, productGroup, " ");
- }
- }
- catch (Exception ex)
- {
- interpreter.printStackTrace(ex);
- }
-
- return null;
- }
-
- public Object _acceptors(CommandInterpreter interpreter)
- {
- try
- {
- printFactoryTypes(interpreter, AcceptorFactory.PRODUCT_GROUP, "");
- }
- catch (Exception ex)
- {
- interpreter.printStackTrace(ex);
- }
-
- return null;
- }
-
- public Object _connectors(CommandInterpreter interpreter)
- {
- try
- {
- printFactoryTypes(interpreter, ConnectorFactory.PRODUCT_GROUP, "");
- }
- catch (Exception ex)
- {
- interpreter.printStackTrace(ex);
- }
-
- return null;
- }
-
- protected IPluginContainer getContainer()
- {
- return IPluginContainer.INSTANCE;
- }
-
- private void printFactoryTypes(CommandInterpreter interpreter, String productGroup, String prefix)
- {
- IPluginContainer container = getContainer();
- for (String factoryType : container.getFactoryTypes(productGroup))
- {
- interpreter.println(prefix + factoryType);
- printElements(interpreter, container.getElements(productGroup, factoryType), prefix + " ");
- }
- }
-
- private void printElements(CommandInterpreter interpreter, Object[] elements, String prefix)
- {
- for (Object element : elements)
- {
- interpreter.println(prefix + element);
- if (element instanceof IContainer)
- {
- IContainer<?> container = (IContainer<?>)element;
- printElements(interpreter, container.getElements(), prefix + " ");
- }
- }
- }
-}
+/*
+ * 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.internal.net4j.bundle;
+
+import org.eclipse.net4j.util.container.IContainer;
+import org.eclipse.net4j.util.container.IPluginContainer;
+
+import org.eclipse.osgi.framework.console.CommandInterpreter;
+import org.eclipse.osgi.framework.console.CommandProvider;
+import org.eclipse.spi.net4j.AcceptorFactory;
+import org.eclipse.spi.net4j.ConnectorFactory;
+
+import org.osgi.framework.BundleContext;
+
+/**
+ * @author Eike Stepper
+ */
+public class Net4jCommandProvider implements CommandProvider
+{
+ public Net4jCommandProvider(BundleContext bundleContext)
+ {
+ bundleContext.registerService(CommandProvider.class.getName(), this, null);
+ }
+
+ public String getHelp()
+ {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append("---Net4j commands---\n");
+ buffer.append("\telements - list all managed elements\n");
+ buffer.append("\tacceptors - list all active acceptors, their connectors and channels\n");
+ buffer.append("\tconnectors - list all active connectors and their channels\n");
+ return buffer.toString();
+ }
+
+ public Object _elements(CommandInterpreter interpreter)
+ {
+ try
+ {
+ for (String productGroup : getContainer().getProductGroups())
+ {
+ interpreter.println(productGroup);
+ printFactoryTypes(interpreter, productGroup, " ");
+ }
+ }
+ catch (Exception ex)
+ {
+ interpreter.printStackTrace(ex);
+ }
+
+ return null;
+ }
+
+ public Object _acceptors(CommandInterpreter interpreter)
+ {
+ try
+ {
+ printFactoryTypes(interpreter, AcceptorFactory.PRODUCT_GROUP, "");
+ }
+ catch (Exception ex)
+ {
+ interpreter.printStackTrace(ex);
+ }
+
+ return null;
+ }
+
+ public Object _connectors(CommandInterpreter interpreter)
+ {
+ try
+ {
+ printFactoryTypes(interpreter, ConnectorFactory.PRODUCT_GROUP, "");
+ }
+ catch (Exception ex)
+ {
+ interpreter.printStackTrace(ex);
+ }
+
+ return null;
+ }
+
+ protected IPluginContainer getContainer()
+ {
+ return IPluginContainer.INSTANCE;
+ }
+
+ private void printFactoryTypes(CommandInterpreter interpreter, String productGroup, String prefix)
+ {
+ IPluginContainer container = getContainer();
+ for (String factoryType : container.getFactoryTypes(productGroup))
+ {
+ interpreter.println(prefix + factoryType);
+ printElements(interpreter, container.getElements(productGroup, factoryType), prefix + " ");
+ }
+ }
+
+ private void printElements(CommandInterpreter interpreter, Object[] elements, String prefix)
+ {
+ for (Object element : elements)
+ {
+ interpreter.println(prefix + element);
+ if (element instanceof IContainer)
+ {
+ IContainer<?> container = (IContainer<?>)element;
+ printElements(interpreter, container.getElements(), prefix + " ");
+ }
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/OM.java b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/OM.java
index 29b3d9ace1..e45ed99ae4 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/OM.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/internal/net4j/bundle/OM.java
@@ -1,65 +1,65 @@
-/*
- * 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.internal.net4j.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"; //$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 OMTracer DEBUG_BUFFER = DEBUG.tracer("buffer"); //$NON-NLS-1$
-
- public static final OMTracer DEBUG_BUFFER_STREAM = DEBUG_BUFFER.tracer("stream"); //$NON-NLS-1$
-
- public static final OMTracer DEBUG_CHANNEL = DEBUG.tracer("channel"); //$NON-NLS-1$
-
- public static final OMTracer DEBUG_ACCEPTOR = DEBUG.tracer("acceptor"); //$NON-NLS-1$
-
- public static final OMTracer DEBUG_CONNECTOR = DEBUG.tracer("connector"); //$NON-NLS-1$
-
- public static final OMTracer DEBUG_SIGNAL = DEBUG.tracer("signal"); //$NON-NLS-1$
-
- public static final boolean SET_SIGNAL_THREAD_NAME = BUNDLE.getDebugSupport().getDebugOption(
- "set.signal.thread.name", false); //$NON-NLS-1$
-
- public static final OMLogger LOG = BUNDLE.logger();
-
- /**
- * @author Eike Stepper
- */
- public static final class Activator extends OSGiActivator
- {
- public Activator()
- {
- super(BUNDLE);
- }
-
- @Override
- protected void doStart() throws Exception
- {
- new Net4jCommandProvider(bundleContext);
- }
- }
-}
+/*
+ * 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.internal.net4j.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"; //$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 OMTracer DEBUG_BUFFER = DEBUG.tracer("buffer"); //$NON-NLS-1$
+
+ public static final OMTracer DEBUG_BUFFER_STREAM = DEBUG_BUFFER.tracer("stream"); //$NON-NLS-1$
+
+ public static final OMTracer DEBUG_CHANNEL = DEBUG.tracer("channel"); //$NON-NLS-1$
+
+ public static final OMTracer DEBUG_ACCEPTOR = DEBUG.tracer("acceptor"); //$NON-NLS-1$
+
+ public static final OMTracer DEBUG_CONNECTOR = DEBUG.tracer("connector"); //$NON-NLS-1$
+
+ public static final OMTracer DEBUG_SIGNAL = DEBUG.tracer("signal"); //$NON-NLS-1$
+
+ public static final boolean SET_SIGNAL_THREAD_NAME = BUNDLE.getDebugSupport().getDebugOption(
+ "set.signal.thread.name", false); //$NON-NLS-1$
+
+ public static final OMLogger LOG = BUNDLE.logger();
+
+ /**
+ * @author Eike Stepper
+ */
+ public static final class Activator extends OSGiActivator
+ {
+ public Activator()
+ {
+ super(BUNDLE);
+ }
+
+ @Override
+ protected void doStart() throws Exception
+ {
+ new Net4jCommandProvider(bundleContext);
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/ContainerProtocolProvider.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/ContainerProtocolProvider.java
index f7f6e443f7..21188d9489 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/ContainerProtocolProvider.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/ContainerProtocolProvider.java
@@ -1,83 +1,83 @@
-/*
- * 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;
-
-import org.eclipse.net4j.protocol.IProtocol;
-import org.eclipse.net4j.protocol.IProtocolProvider;
-import org.eclipse.net4j.util.concurrent.NonBlockingLongCounter;
-import org.eclipse.net4j.util.container.IManagedContainer;
-
-import org.eclipse.spi.net4j.ClientProtocolFactory;
-import org.eclipse.spi.net4j.ServerProtocolFactory;
-
-/**
- * Base class for container-based {@link IProtocolProvider protocol providers} like {@link Client} or {@link Server}.
- *
- * @author Eike Stepper
- * @since 2.0
- */
-public abstract class ContainerProtocolProvider implements IProtocolProvider
-{
- private static NonBlockingLongCounter counter = new NonBlockingLongCounter();
-
- private IManagedContainer container;
-
- private String productGroup;
-
- protected ContainerProtocolProvider(IManagedContainer container, String productGroup)
- {
- this.container = container;
- this.productGroup = productGroup;
- }
-
- public IManagedContainer getContainer()
- {
- return container;
- }
-
- public String getProductGroup()
- {
- return productGroup;
- }
-
- public IProtocol<?> getProtocol(String type)
- {
- return (IProtocol<?>)container.getElement(productGroup, type, "protocol-" + counter.increment(), false); //$NON-NLS-1$
- }
-
- /**
- * Container-based {@link IProtocolProvider protocol provider} for {@link ILocationAware.Location#CLIENT client}
- * protocols.
- *
- * @author Eike Stepper
- */
- public static class Client extends ContainerProtocolProvider
- {
- public Client(IManagedContainer container)
- {
- super(container, ClientProtocolFactory.PRODUCT_GROUP);
- }
- }
-
- /**
- * Container-based {@link IProtocolProvider protocol provider} for {@link ILocationAware.Location#SERVER server}
- * protocols.
- *
- * @author Eike Stepper
- */
- public static class Server extends ContainerProtocolProvider
- {
- public Server(IManagedContainer container)
- {
- super(container, ServerProtocolFactory.PRODUCT_GROUP);
- }
- }
-}
+/*
+ * 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;
+
+import org.eclipse.net4j.protocol.IProtocol;
+import org.eclipse.net4j.protocol.IProtocolProvider;
+import org.eclipse.net4j.util.concurrent.NonBlockingLongCounter;
+import org.eclipse.net4j.util.container.IManagedContainer;
+
+import org.eclipse.spi.net4j.ClientProtocolFactory;
+import org.eclipse.spi.net4j.ServerProtocolFactory;
+
+/**
+ * Base class for container-based {@link IProtocolProvider protocol providers} like {@link Client} or {@link Server}.
+ *
+ * @author Eike Stepper
+ * @since 2.0
+ */
+public abstract class ContainerProtocolProvider implements IProtocolProvider
+{
+ private static NonBlockingLongCounter counter = new NonBlockingLongCounter();
+
+ private IManagedContainer container;
+
+ private String productGroup;
+
+ protected ContainerProtocolProvider(IManagedContainer container, String productGroup)
+ {
+ this.container = container;
+ this.productGroup = productGroup;
+ }
+
+ public IManagedContainer getContainer()
+ {
+ return container;
+ }
+
+ public String getProductGroup()
+ {
+ return productGroup;
+ }
+
+ public IProtocol<?> getProtocol(String type)
+ {
+ return (IProtocol<?>)container.getElement(productGroup, type, "protocol-" + counter.increment(), false); //$NON-NLS-1$
+ }
+
+ /**
+ * Container-based {@link IProtocolProvider protocol provider} for {@link ILocationAware.Location#CLIENT client}
+ * protocols.
+ *
+ * @author Eike Stepper
+ */
+ public static class Client extends ContainerProtocolProvider
+ {
+ public Client(IManagedContainer container)
+ {
+ super(container, ClientProtocolFactory.PRODUCT_GROUP);
+ }
+ }
+
+ /**
+ * Container-based {@link IProtocolProvider protocol provider} for {@link ILocationAware.Location#SERVER server}
+ * protocols.
+ *
+ * @author Eike Stepper
+ */
+ public static class Server extends ContainerProtocolProvider
+ {
+ public Server(IManagedContainer container)
+ {
+ super(container, ServerProtocolFactory.PRODUCT_GROUP);
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/FactoriesProtocolProvider.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/FactoriesProtocolProvider.java
index 439b4a8bb4..7fd186597b 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/FactoriesProtocolProvider.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/FactoriesProtocolProvider.java
@@ -1,73 +1,73 @@
-/*
- * 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;
-
-import org.eclipse.net4j.protocol.IProtocol;
-import org.eclipse.net4j.protocol.IProtocolProvider;
-import org.eclipse.net4j.util.factory.IFactory;
-import org.eclipse.net4j.util.registry.HashMapRegistry;
-import org.eclipse.net4j.util.registry.IRegistry;
-
-/**
- * Factory-based {@link IProtocolProvider protocol provider}.
- *
- * @author Eike Stepper
- * @since 2.0
- */
-public class FactoriesProtocolProvider implements IProtocolProvider
-{
- private IRegistry<String, IFactory> registry;
-
- public FactoriesProtocolProvider()
- {
- }
-
- public FactoriesProtocolProvider(IRegistry<String, IFactory> registry)
- {
- setRegistry(registry);
- }
-
- public FactoriesProtocolProvider(IFactory factory)
- {
- addFactory(factory);
- }
-
- public IRegistry<String, IFactory> getRegistry()
- {
- if (registry == null)
- {
- registry = new HashMapRegistry<String, IFactory>();
- }
-
- return registry;
- }
-
- public void setRegistry(IRegistry<String, IFactory> registry)
- {
- this.registry = registry;
- }
-
- public void addFactory(IFactory factory)
- {
- getRegistry().put(factory.getKey().getType(), factory);
- }
-
- public IProtocol<?> getProtocol(String type)
- {
- IFactory factory = registry.get(type);
- if (factory != null)
- {
- return (IProtocol<?>)factory.create(null);
- }
-
- return null;
- }
-}
+/*
+ * 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;
+
+import org.eclipse.net4j.protocol.IProtocol;
+import org.eclipse.net4j.protocol.IProtocolProvider;
+import org.eclipse.net4j.util.factory.IFactory;
+import org.eclipse.net4j.util.registry.HashMapRegistry;
+import org.eclipse.net4j.util.registry.IRegistry;
+
+/**
+ * Factory-based {@link IProtocolProvider protocol provider}.
+ *
+ * @author Eike Stepper
+ * @since 2.0
+ */
+public class FactoriesProtocolProvider implements IProtocolProvider
+{
+ private IRegistry<String, IFactory> registry;
+
+ public FactoriesProtocolProvider()
+ {
+ }
+
+ public FactoriesProtocolProvider(IRegistry<String, IFactory> registry)
+ {
+ setRegistry(registry);
+ }
+
+ public FactoriesProtocolProvider(IFactory factory)
+ {
+ addFactory(factory);
+ }
+
+ public IRegistry<String, IFactory> getRegistry()
+ {
+ if (registry == null)
+ {
+ registry = new HashMapRegistry<String, IFactory>();
+ }
+
+ return registry;
+ }
+
+ public void setRegistry(IRegistry<String, IFactory> registry)
+ {
+ this.registry = registry;
+ }
+
+ public void addFactory(IFactory factory)
+ {
+ getRegistry().put(factory.getKey().getType(), factory);
+ }
+
+ public IProtocol<?> getProtocol(String type)
+ {
+ IFactory factory = registry.get(type);
+ if (factory != null)
+ {
+ return (IProtocol<?>)factory.create(null);
+ }
+
+ return null;
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/ILocationAware.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/ILocationAware.java
index 824305b7a6..b4c521ab23 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/ILocationAware.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/ILocationAware.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;
-
-/**
- * A concept that has a {@link Location location} in a {@link Location#CLIENT client}/{@link Location#SERVER server}
- * scenario.
- *
- * @author Eike Stepper
- * @since 2.0
- */
-public interface ILocationAware
-{
- /**
- * Returns the location of this object in a {@link Location#CLIENT client}/{@link Location#SERVER server} scenario.
- */
- public Location getLocation();
-
- /**
- * Same as <code>{@link #getLocation()} == {@link Location#CLIENT}</code>.
- */
- public boolean isClient();
-
- /**
- * Same as <code>{@link #getLocation()} == {@link Location#SERVER}</code>.
- */
- public boolean isServer();
-
- /**
- * A {@link Location location} in a {@link Location#CLIENT client}/{@link Location#SERVER server} scenario.
- *
- * @author Eike Stepper
- * @since 2.0
- */
- public enum Location
- {
- CLIENT, SERVER
- }
-}
+/*
+ * 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;
+
+/**
+ * A concept that has a {@link Location location} in a {@link Location#CLIENT client}/{@link Location#SERVER server}
+ * scenario.
+ *
+ * @author Eike Stepper
+ * @since 2.0
+ */
+public interface ILocationAware
+{
+ /**
+ * Returns the location of this object in a {@link Location#CLIENT client}/{@link Location#SERVER server} scenario.
+ */
+ public Location getLocation();
+
+ /**
+ * Same as <code>{@link #getLocation()} == {@link Location#CLIENT}</code>.
+ */
+ public boolean isClient();
+
+ /**
+ * Same as <code>{@link #getLocation()} == {@link Location#SERVER}</code>.
+ */
+ public boolean isServer();
+
+ /**
+ * A {@link Location location} in a {@link Location#CLIENT client}/{@link Location#SERVER server} scenario.
+ *
+ * @author Eike Stepper
+ * @since 2.0
+ */
+ public enum Location
+ {
+ CLIENT, SERVER
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/ITransportConfig.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/ITransportConfig.java
index 6b5ab60c31..cccd2fd9dc 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/ITransportConfig.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/ITransportConfig.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;
-
-import org.eclipse.net4j.acceptor.IAcceptor;
-import org.eclipse.net4j.buffer.IBufferProvider;
-import org.eclipse.net4j.channel.IChannelMultiplexer;
-import org.eclipse.net4j.connector.IConnector;
-import org.eclipse.net4j.protocol.IProtocolProvider;
-import org.eclipse.net4j.util.lifecycle.ILifecycle;
-import org.eclipse.net4j.util.security.INegotiatorAware;
-
-import java.util.concurrent.ExecutorService;
-
-/**
- * A common transport configuration that specifies basic dependencies for {@link IChannelMultiplexer channel
- * multiplexers}, {@link IConnector connectors} and {@link IAcceptor acceptors}.
- *
- * @author Eike Stepper
- * @since 2.0
- * @noextend This interface is not intended to be extended by clients.
- * @noimplement This interface is not intended to be implemented by clients.
- */
-public interface ITransportConfig extends INegotiatorAware
-{
- /**
- * Returns the lifecycle delegate used for inactivity checks in the setter implementations of this transport
- * configuration.
- */
- public ILifecycle getLifecycle();
-
- /**
- * Sets the lifecycle delegate to be used for inactivity checks in the setter implementations of this transport
- * configuration.
- */
- public void setLifecycle(ILifecycle lifecycle);
-
- public IBufferProvider getBufferProvider();
-
- public void setBufferProvider(IBufferProvider bufferProvider);
-
- public ExecutorService getReceiveExecutor();
-
- public void setReceiveExecutor(ExecutorService receiveExecutor);
-
- public IProtocolProvider getProtocolProvider();
-
- public void setProtocolProvider(IProtocolProvider protocolProvider);
-}
+/*
+ * 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;
+
+import org.eclipse.net4j.acceptor.IAcceptor;
+import org.eclipse.net4j.buffer.IBufferProvider;
+import org.eclipse.net4j.channel.IChannelMultiplexer;
+import org.eclipse.net4j.connector.IConnector;
+import org.eclipse.net4j.protocol.IProtocolProvider;
+import org.eclipse.net4j.util.lifecycle.ILifecycle;
+import org.eclipse.net4j.util.security.INegotiatorAware;
+
+import java.util.concurrent.ExecutorService;
+
+/**
+ * A common transport configuration that specifies basic dependencies for {@link IChannelMultiplexer channel
+ * multiplexers}, {@link IConnector connectors} and {@link IAcceptor acceptors}.
+ *
+ * @author Eike Stepper
+ * @since 2.0
+ * @noextend This interface is not intended to be extended by clients.
+ * @noimplement This interface is not intended to be implemented by clients.
+ */
+public interface ITransportConfig extends INegotiatorAware
+{
+ /**
+ * Returns the lifecycle delegate used for inactivity checks in the setter implementations of this transport
+ * configuration.
+ */
+ public ILifecycle getLifecycle();
+
+ /**
+ * Sets the lifecycle delegate to be used for inactivity checks in the setter implementations of this transport
+ * configuration.
+ */
+ public void setLifecycle(ILifecycle lifecycle);
+
+ public IBufferProvider getBufferProvider();
+
+ public void setBufferProvider(IBufferProvider bufferProvider);
+
+ public ExecutorService getReceiveExecutor();
+
+ public void setReceiveExecutor(ExecutorService receiveExecutor);
+
+ public IProtocolProvider getProtocolProvider();
+
+ public void setProtocolProvider(IProtocolProvider protocolProvider);
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/ITransportConfigAware.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/ITransportConfigAware.java
index b0fdbf3913..a8a92989aa 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/ITransportConfigAware.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/ITransportConfigAware.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;
-
-import org.eclipse.net4j.acceptor.IAcceptor;
-import org.eclipse.net4j.channel.IChannelMultiplexer;
-import org.eclipse.net4j.connector.IConnector;
-
-/**
- * A concept that has a {@link ITransportConfig transport configuration}, typically a {@link IChannelMultiplexer channel
- * multiplexer}, {@link IConnector connector} or {@link IAcceptor acceptor}.
- *
- * @author Eike Stepper
- * @since 2.0
- */
-public interface ITransportConfigAware
-{
- /**
- * Returns the current transport configuration if there is one, a new empty one otherwise.
- */
- public ITransportConfig getConfig();
-
- /**
- * Sets a new transport configuration by <b>copying</b> the given one.
- */
- public void setConfig(ITransportConfig config);
-}
+/*
+ * 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;
+
+import org.eclipse.net4j.acceptor.IAcceptor;
+import org.eclipse.net4j.channel.IChannelMultiplexer;
+import org.eclipse.net4j.connector.IConnector;
+
+/**
+ * A concept that has a {@link ITransportConfig transport configuration}, typically a {@link IChannelMultiplexer channel
+ * multiplexer}, {@link IConnector connector} or {@link IAcceptor acceptor}.
+ *
+ * @author Eike Stepper
+ * @since 2.0
+ */
+public interface ITransportConfigAware
+{
+ /**
+ * Returns the current transport configuration if there is one, a new empty one otherwise.
+ */
+ public ITransportConfig getConfig();
+
+ /**
+ * Sets a new transport configuration by <b>copying</b> the given one.
+ */
+ public void setConfig(ITransportConfig config);
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/Net4jUtil.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/Net4jUtil.java
index fb80d8487b..e0d0b73508 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/Net4jUtil.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/Net4jUtil.java
@@ -1,181 +1,181 @@
-/*
- * 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;
-
-import org.eclipse.net4j.acceptor.IAcceptor;
-import org.eclipse.net4j.buffer.IBufferPool;
-import org.eclipse.net4j.buffer.IBufferProvider;
-import org.eclipse.net4j.connector.ConnectorException;
-import org.eclipse.net4j.connector.IConnector;
-import org.eclipse.net4j.signal.heartbeat.HeartBeatProtocol;
-import org.eclipse.net4j.util.StringUtil;
-import org.eclipse.net4j.util.concurrent.ExecutorServiceFactory;
-import org.eclipse.net4j.util.container.ContainerUtil;
-import org.eclipse.net4j.util.container.IManagedContainer;
-import org.eclipse.net4j.util.lifecycle.ILifecycle;
-
-import org.eclipse.internal.net4j.TransportConfig;
-import org.eclipse.internal.net4j.buffer.BufferFactory;
-import org.eclipse.internal.net4j.buffer.BufferPool;
-import org.eclipse.internal.net4j.buffer.BufferProviderFactory;
-
-import org.eclipse.spi.net4j.AcceptorFactory;
-import org.eclipse.spi.net4j.ConnectorFactory;
-
-import java.util.concurrent.ExecutorService;
-
-/**
- * A utility class with various static factory and convenience methods.
- *
- * @author Eike Stepper
- */
-public final class Net4jUtil
-{
- public static final String SCHEME_SEPARATOR = "://"; //$NON-NLS-1$
-
- public static final short DEFAULT_BUFFER_CAPACITY = 4096;
-
- private Net4jUtil()
- {
- }
-
- public static void prepareContainer(IManagedContainer container)
- {
- ContainerUtil.prepareContainer(container);
- container.registerFactory(new BufferProviderFactory());
- container.addPostProcessor(new TransportInjector());
- container.registerFactory(new HeartBeatProtocol.Server.Factory());
- container.addPostProcessor(new HeartBeatProtocol.Server.TimerInjector());
- }
-
- public static ExecutorService getExecutorService(IManagedContainer container)
- {
- return ExecutorServiceFactory.get(container);
- }
-
- public static IBufferProvider getBufferProvider(IManagedContainer container)
- {
- return BufferProviderFactory.get(container);
- }
-
- public static IAcceptor getAcceptor(IManagedContainer container, String type, String description)
- {
- return (IAcceptor)container.getElement(AcceptorFactory.PRODUCT_GROUP, type, description);
- }
-
- /**
- * @since 4.0
- */
- public static IConnector getConnector(IManagedContainer container, String type, String description, long timeout)
- {
- IConnector connector = (IConnector)container.getElement(ConnectorFactory.PRODUCT_GROUP, type, description);
-
- try
- {
- connector.waitForConnection(timeout);
- }
- catch (ConnectorException ex)
- {
- container.removeElement(ConnectorFactory.PRODUCT_GROUP, type, description);
- throw ex;
- }
-
- return connector;
- }
-
- public static IConnector getConnector(IManagedContainer container, String type, String description)
- {
- return getConnector(container, type, description, 10000L);
- }
-
- public static IConnector getConnector(IManagedContainer container, String description)
- {
- int pos = description.indexOf(SCHEME_SEPARATOR);
- if (pos <= 0)
- {
- throw new IllegalArgumentException("Connector type (scheme) missing: " + description); //$NON-NLS-1$
- }
-
- String factoryType = description.substring(0, pos);
-
- String connectorDescription = description.substring(pos + SCHEME_SEPARATOR.length());
- if (StringUtil.isEmpty(connectorDescription))
- {
- throw new IllegalArgumentException("Illegal connector description: " + description); //$NON-NLS-1$
- }
-
- return getConnector(container, factoryType, connectorDescription);
- }
-
- public static IBufferProvider createBufferFactory(short bufferCapacity)
- {
- return new BufferFactory(bufferCapacity);
- }
-
- public static IBufferProvider createBufferFactory()
- {
- return createBufferFactory(DEFAULT_BUFFER_CAPACITY);
- }
-
- public static IBufferPool createBufferPool(IBufferProvider factory)
- {
- return new BufferPool(factory);
- }
-
- public static IBufferPool createBufferPool(short bufferCapacity)
- {
- return createBufferPool(createBufferFactory(bufferCapacity));
- }
-
- public static IBufferPool createBufferPool()
- {
- return createBufferPool(createBufferFactory());
- }
-
- public static long getProvidedBuffers(IBufferProvider bufferProvider)
- {
- if (bufferProvider instanceof IBufferProvider.Introspection)
- {
- return ((IBufferProvider.Introspection)bufferProvider).getProvidedBuffers();
- }
-
- return -1L;
- }
-
- public static long getRetainedBuffers(IBufferProvider bufferProvider)
- {
- if (bufferProvider instanceof IBufferProvider.Introspection)
- {
- return ((IBufferProvider.Introspection)bufferProvider).getRetainedBuffers();
- }
-
- return -1L;
- }
-
- public static int getPooledBuffers(IBufferPool bufferPool)
- {
- if (bufferPool instanceof IBufferPool.Introspection)
- {
- return ((IBufferPool.Introspection)bufferPool).getPooledBuffers();
- }
-
- return -1;
- }
-
- /**
- * @since 2.0
- */
- public static ITransportConfig copyTransportConfig(ILifecycle lifecycle, ITransportConfig source)
- {
- return new TransportConfig(lifecycle, source.getReceiveExecutor(), source.getBufferProvider(),
- source.getProtocolProvider(), source.getNegotiator());
- }
-}
+/*
+ * 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;
+
+import org.eclipse.net4j.acceptor.IAcceptor;
+import org.eclipse.net4j.buffer.IBufferPool;
+import org.eclipse.net4j.buffer.IBufferProvider;
+import org.eclipse.net4j.connector.ConnectorException;
+import org.eclipse.net4j.connector.IConnector;
+import org.eclipse.net4j.signal.heartbeat.HeartBeatProtocol;
+import org.eclipse.net4j.util.StringUtil;
+import org.eclipse.net4j.util.concurrent.ExecutorServiceFactory;
+import org.eclipse.net4j.util.container.ContainerUtil;
+import org.eclipse.net4j.util.container.IManagedContainer;
+import org.eclipse.net4j.util.lifecycle.ILifecycle;
+
+import org.eclipse.internal.net4j.TransportConfig;
+import org.eclipse.internal.net4j.buffer.BufferFactory;
+import org.eclipse.internal.net4j.buffer.BufferPool;
+import org.eclipse.internal.net4j.buffer.BufferProviderFactory;
+
+import org.eclipse.spi.net4j.AcceptorFactory;
+import org.eclipse.spi.net4j.ConnectorFactory;
+
+import java.util.concurrent.ExecutorService;
+
+/**
+ * A utility class with various static factory and convenience methods.
+ *
+ * @author Eike Stepper
+ */
+public final class Net4jUtil
+{
+ public static final String SCHEME_SEPARATOR = "://"; //$NON-NLS-1$
+
+ public static final short DEFAULT_BUFFER_CAPACITY = 4096;
+
+ private Net4jUtil()
+ {
+ }
+
+ public static void prepareContainer(IManagedContainer container)
+ {
+ ContainerUtil.prepareContainer(container);
+ container.registerFactory(new BufferProviderFactory());
+ container.addPostProcessor(new TransportInjector());
+ container.registerFactory(new HeartBeatProtocol.Server.Factory());
+ container.addPostProcessor(new HeartBeatProtocol.Server.TimerInjector());
+ }
+
+ public static ExecutorService getExecutorService(IManagedContainer container)
+ {
+ return ExecutorServiceFactory.get(container);
+ }
+
+ public static IBufferProvider getBufferProvider(IManagedContainer container)
+ {
+ return BufferProviderFactory.get(container);
+ }
+
+ public static IAcceptor getAcceptor(IManagedContainer container, String type, String description)
+ {
+ return (IAcceptor)container.getElement(AcceptorFactory.PRODUCT_GROUP, type, description);
+ }
+
+ /**
+ * @since 4.0
+ */
+ public static IConnector getConnector(IManagedContainer container, String type, String description, long timeout)
+ {
+ IConnector connector = (IConnector)container.getElement(ConnectorFactory.PRODUCT_GROUP, type, description);
+
+ try
+ {
+ connector.waitForConnection(timeout);
+ }
+ catch (ConnectorException ex)
+ {
+ container.removeElement(ConnectorFactory.PRODUCT_GROUP, type, description);
+ throw ex;
+ }
+
+ return connector;
+ }
+
+ public static IConnector getConnector(IManagedContainer container, String type, String description)
+ {
+ return getConnector(container, type, description, 10000L);
+ }
+
+ public static IConnector getConnector(IManagedContainer container, String description)
+ {
+ int pos = description.indexOf(SCHEME_SEPARATOR);
+ if (pos <= 0)
+ {
+ throw new IllegalArgumentException("Connector type (scheme) missing: " + description); //$NON-NLS-1$
+ }
+
+ String factoryType = description.substring(0, pos);
+
+ String connectorDescription = description.substring(pos + SCHEME_SEPARATOR.length());
+ if (StringUtil.isEmpty(connectorDescription))
+ {
+ throw new IllegalArgumentException("Illegal connector description: " + description); //$NON-NLS-1$
+ }
+
+ return getConnector(container, factoryType, connectorDescription);
+ }
+
+ public static IBufferProvider createBufferFactory(short bufferCapacity)
+ {
+ return new BufferFactory(bufferCapacity);
+ }
+
+ public static IBufferProvider createBufferFactory()
+ {
+ return createBufferFactory(DEFAULT_BUFFER_CAPACITY);
+ }
+
+ public static IBufferPool createBufferPool(IBufferProvider factory)
+ {
+ return new BufferPool(factory);
+ }
+
+ public static IBufferPool createBufferPool(short bufferCapacity)
+ {
+ return createBufferPool(createBufferFactory(bufferCapacity));
+ }
+
+ public static IBufferPool createBufferPool()
+ {
+ return createBufferPool(createBufferFactory());
+ }
+
+ public static long getProvidedBuffers(IBufferProvider bufferProvider)
+ {
+ if (bufferProvider instanceof IBufferProvider.Introspection)
+ {
+ return ((IBufferProvider.Introspection)bufferProvider).getProvidedBuffers();
+ }
+
+ return -1L;
+ }
+
+ public static long getRetainedBuffers(IBufferProvider bufferProvider)
+ {
+ if (bufferProvider instanceof IBufferProvider.Introspection)
+ {
+ return ((IBufferProvider.Introspection)bufferProvider).getRetainedBuffers();
+ }
+
+ return -1L;
+ }
+
+ public static int getPooledBuffers(IBufferPool bufferPool)
+ {
+ if (bufferPool instanceof IBufferPool.Introspection)
+ {
+ return ((IBufferPool.Introspection)bufferPool).getPooledBuffers();
+ }
+
+ return -1;
+ }
+
+ /**
+ * @since 2.0
+ */
+ public static ITransportConfig copyTransportConfig(ILifecycle lifecycle, ITransportConfig source)
+ {
+ return new TransportConfig(lifecycle, source.getReceiveExecutor(), source.getBufferProvider(),
+ source.getProtocolProvider(), source.getNegotiator());
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/TransportConfigurator.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/TransportConfigurator.java
index 6bc081d1d0..0f23441710 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/TransportConfigurator.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/TransportConfigurator.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
- */
-package org.eclipse.net4j;
-
-import org.eclipse.net4j.acceptor.IAcceptor;
-import org.eclipse.net4j.util.container.IManagedContainer;
-import org.eclipse.net4j.util.om.trace.ContextTracer;
-import org.eclipse.net4j.util.security.INegotiator;
-import org.eclipse.net4j.util.security.NegotiatorFactory;
-
-import org.eclipse.internal.net4j.bundle.OM;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.spi.net4j.Acceptor;
-import org.eclipse.spi.net4j.AcceptorFactory;
-
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.xml.sax.SAXException;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * Reads an XML config file and creates, wires and starts the configured {@link IAcceptor acceptors}.
- *
- * @author Eike Stepper
- * @since 2.0
- */
-public class TransportConfigurator
-{
- private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, TransportConfigurator.class);
-
- private IManagedContainer container;
-
- public TransportConfigurator(IManagedContainer container)
- {
- this.container = container;
- }
-
- public IManagedContainer getContainer()
- {
- return container;
- }
-
- public IAcceptor[] configure(File configFile) throws ParserConfigurationException, SAXException, IOException,
- CoreException
- {
- if (TRACER.isEnabled())
- {
- TRACER.trace("Configuring Net4j server from " + configFile.getAbsolutePath()); //$NON-NLS-1$
- }
-
- List<IAcceptor> acceptors = new ArrayList<IAcceptor>();
- Document document = getDocument(configFile);
- NodeList acceptorConfigs = document.getElementsByTagName("acceptor"); //$NON-NLS-1$
- for (int i = 0; i < acceptorConfigs.getLength(); i++)
- {
- Element acceptorConfig = (Element)acceptorConfigs.item(i);
- IAcceptor acceptor = configureAcceptor(acceptorConfig);
- acceptors.add(acceptor);
- }
-
- return acceptors.toArray(new IAcceptor[acceptors.size()]);
- }
-
- protected IAcceptor configureAcceptor(Element acceptorConfig)
- {
- String type = acceptorConfig.getAttribute("type"); //$NON-NLS-1$
- // TODO Make the following dependent on the "type" attribute value
- String listenAddr = acceptorConfig.getAttribute("listenAddr"); //$NON-NLS-1$
- String port = acceptorConfig.getAttribute("port"); //$NON-NLS-1$
- String description = (listenAddr == null ? "" : listenAddr) + (port == null ? "" : ":" + port); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- Acceptor acceptor = (Acceptor)container.getElement(AcceptorFactory.PRODUCT_GROUP, type, description, false);
-
- NodeList negotiatorConfigs = acceptorConfig.getElementsByTagName("negotiator"); //$NON-NLS-1$
- if (negotiatorConfigs.getLength() > 1)
- {
- throw new IllegalStateException("A maximum of one negotiator can be configured for acceptor " + acceptor); //$NON-NLS-1$
- }
-
- if (negotiatorConfigs.getLength() == 1)
- {
- Element negotiatorConfig = (Element)negotiatorConfigs.item(0);
- INegotiator negotiator = configureNegotiator(negotiatorConfig);
- acceptor.getConfig().setNegotiator(negotiator);
- }
-
- acceptor.activate();
- return acceptor;
- }
-
- protected INegotiator configureNegotiator(Element negotiatorConfig)
- {
- String type = negotiatorConfig.getAttribute("type"); //$NON-NLS-1$
- String description = negotiatorConfig.getAttribute("description"); //$NON-NLS-1$
- return (INegotiator)container.getElement(NegotiatorFactory.PRODUCT_GROUP, type, description);
- }
-
- protected Document getDocument(File configFile) throws ParserConfigurationException, SAXException, IOException
- {
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
- DocumentBuilder builder = factory.newDocumentBuilder();
- return builder.parse(configFile);
- }
-
- protected Element getStoreConfig(Element repositoryConfig)
- {
- NodeList storeConfigs = repositoryConfig.getElementsByTagName("store"); //$NON-NLS-1$
- if (storeConfigs.getLength() != 1)
- {
- String repositoryName = repositoryConfig.getAttribute("name"); //$NON-NLS-1$
- throw new IllegalStateException("Exactly one store must be configured for repository " + repositoryName); //$NON-NLS-1$
- }
-
- return (Element)storeConfigs.item(0);
- }
-
- public static Map<String, String> getProperties(Element element, int levels)
- {
- Map<String, String> properties = new HashMap<String, String>();
- collectProperties(element, "", properties, levels); //$NON-NLS-1$
- return properties;
- }
-
- private static void collectProperties(Element element, String prefix, Map<String, String> properties, int levels)
- {
- if ("property".equals(element.getNodeName())) //$NON-NLS-1$
- {
- String name = element.getAttribute("name"); //$NON-NLS-1$
- String value = element.getAttribute("value"); //$NON-NLS-1$
- properties.put(prefix + name, value);
- prefix += name + "."; //$NON-NLS-1$
- }
-
- if (levels > 0)
- {
- NodeList childNodes = element.getChildNodes();
- for (int i = 0; i < childNodes.getLength(); i++)
- {
- Node childNode = childNodes.item(i);
- if (childNode instanceof Element)
- {
- collectProperties((Element)childNode, prefix, properties, levels - 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;
+
+import org.eclipse.net4j.acceptor.IAcceptor;
+import org.eclipse.net4j.util.container.IManagedContainer;
+import org.eclipse.net4j.util.om.trace.ContextTracer;
+import org.eclipse.net4j.util.security.INegotiator;
+import org.eclipse.net4j.util.security.NegotiatorFactory;
+
+import org.eclipse.internal.net4j.bundle.OM;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.spi.net4j.Acceptor;
+import org.eclipse.spi.net4j.AcceptorFactory;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Reads an XML config file and creates, wires and starts the configured {@link IAcceptor acceptors}.
+ *
+ * @author Eike Stepper
+ * @since 2.0
+ */
+public class TransportConfigurator
+{
+ private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, TransportConfigurator.class);
+
+ private IManagedContainer container;
+
+ public TransportConfigurator(IManagedContainer container)
+ {
+ this.container = container;
+ }
+
+ public IManagedContainer getContainer()
+ {
+ return container;
+ }
+
+ public IAcceptor[] configure(File configFile) throws ParserConfigurationException, SAXException, IOException,
+ CoreException
+ {
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace("Configuring Net4j server from " + configFile.getAbsolutePath()); //$NON-NLS-1$
+ }
+
+ List<IAcceptor> acceptors = new ArrayList<IAcceptor>();
+ Document document = getDocument(configFile);
+ NodeList acceptorConfigs = document.getElementsByTagName("acceptor"); //$NON-NLS-1$
+ for (int i = 0; i < acceptorConfigs.getLength(); i++)
+ {
+ Element acceptorConfig = (Element)acceptorConfigs.item(i);
+ IAcceptor acceptor = configureAcceptor(acceptorConfig);
+ acceptors.add(acceptor);
+ }
+
+ return acceptors.toArray(new IAcceptor[acceptors.size()]);
+ }
+
+ protected IAcceptor configureAcceptor(Element acceptorConfig)
+ {
+ String type = acceptorConfig.getAttribute("type"); //$NON-NLS-1$
+ // TODO Make the following dependent on the "type" attribute value
+ String listenAddr = acceptorConfig.getAttribute("listenAddr"); //$NON-NLS-1$
+ String port = acceptorConfig.getAttribute("port"); //$NON-NLS-1$
+ String description = (listenAddr == null ? "" : listenAddr) + (port == null ? "" : ":" + port); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ Acceptor acceptor = (Acceptor)container.getElement(AcceptorFactory.PRODUCT_GROUP, type, description, false);
+
+ NodeList negotiatorConfigs = acceptorConfig.getElementsByTagName("negotiator"); //$NON-NLS-1$
+ if (negotiatorConfigs.getLength() > 1)
+ {
+ throw new IllegalStateException("A maximum of one negotiator can be configured for acceptor " + acceptor); //$NON-NLS-1$
+ }
+
+ if (negotiatorConfigs.getLength() == 1)
+ {
+ Element negotiatorConfig = (Element)negotiatorConfigs.item(0);
+ INegotiator negotiator = configureNegotiator(negotiatorConfig);
+ acceptor.getConfig().setNegotiator(negotiator);
+ }
+
+ acceptor.activate();
+ return acceptor;
+ }
+
+ protected INegotiator configureNegotiator(Element negotiatorConfig)
+ {
+ String type = negotiatorConfig.getAttribute("type"); //$NON-NLS-1$
+ String description = negotiatorConfig.getAttribute("description"); //$NON-NLS-1$
+ return (INegotiator)container.getElement(NegotiatorFactory.PRODUCT_GROUP, type, description);
+ }
+
+ protected Document getDocument(File configFile) throws ParserConfigurationException, SAXException, IOException
+ {
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ return builder.parse(configFile);
+ }
+
+ protected Element getStoreConfig(Element repositoryConfig)
+ {
+ NodeList storeConfigs = repositoryConfig.getElementsByTagName("store"); //$NON-NLS-1$
+ if (storeConfigs.getLength() != 1)
+ {
+ String repositoryName = repositoryConfig.getAttribute("name"); //$NON-NLS-1$
+ throw new IllegalStateException("Exactly one store must be configured for repository " + repositoryName); //$NON-NLS-1$
+ }
+
+ return (Element)storeConfigs.item(0);
+ }
+
+ public static Map<String, String> getProperties(Element element, int levels)
+ {
+ Map<String, String> properties = new HashMap<String, String>();
+ collectProperties(element, "", properties, levels); //$NON-NLS-1$
+ return properties;
+ }
+
+ private static void collectProperties(Element element, String prefix, Map<String, String> properties, int levels)
+ {
+ if ("property".equals(element.getNodeName())) //$NON-NLS-1$
+ {
+ String name = element.getAttribute("name"); //$NON-NLS-1$
+ String value = element.getAttribute("value"); //$NON-NLS-1$
+ properties.put(prefix + name, value);
+ prefix += name + "."; //$NON-NLS-1$
+ }
+
+ if (levels > 0)
+ {
+ NodeList childNodes = element.getChildNodes();
+ for (int i = 0; i < childNodes.getLength(); i++)
+ {
+ Node childNode = childNodes.item(i);
+ if (childNode instanceof Element)
+ {
+ collectProperties((Element)childNode, prefix, properties, levels - 1);
+ }
+ }
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/TransportInjector.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/TransportInjector.java
index 6e6fce7cd5..c8807780d6 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/TransportInjector.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/TransportInjector.java
@@ -1,110 +1,110 @@
-/*
- * 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;
-
-import org.eclipse.net4j.acceptor.IAcceptor;
-import org.eclipse.net4j.buffer.IBufferProvider;
-import org.eclipse.net4j.connector.IConnector;
-import org.eclipse.net4j.util.concurrent.ExecutorServiceFactory;
-import org.eclipse.net4j.util.container.IElementProcessor;
-import org.eclipse.net4j.util.container.IManagedContainer;
-
-import org.eclipse.internal.net4j.buffer.BufferProviderFactory;
-
-import org.eclipse.spi.net4j.InternalAcceptor;
-import org.eclipse.spi.net4j.InternalConnector;
-
-import java.util.concurrent.ExecutorService;
-
-/**
- * An element post processor that injects a {@link ITransportConfig transport configuration} into the {@link IConnector
- * connectors} and {@link IAcceptor acceptors} of a {@link IManagedContainer managed container}.
- *
- * @author Eike Stepper
- * @since 2.0
- */
-public class TransportInjector implements IElementProcessor
-{
- public TransportInjector()
- {
- }
-
- public Object process(IManagedContainer container, String productGroup, String factoryType, String description,
- Object element)
- {
- if (element instanceof InternalAcceptor)
- {
- InternalAcceptor acceptor = (InternalAcceptor)element;
- processAcceptor(container, factoryType, description, acceptor);
- }
- else if (element instanceof InternalConnector)
- {
- InternalConnector connector = (InternalConnector)element;
- processConnector(container, factoryType, description, connector);
- }
-
- return element;
- }
-
- protected void processAcceptor(IManagedContainer container, String factoryType, String description,
- InternalAcceptor acceptor)
- {
- ITransportConfig config = acceptor.getConfig();
- if (config.getBufferProvider() == null)
- {
- config.setBufferProvider(getBufferProvider(container));
- }
-
- if (config.getReceiveExecutor() == null)
- {
- config.setReceiveExecutor(getExecutorService(container));
- }
-
- if (config.getProtocolProvider() == null)
- {
- config.setProtocolProvider(new ContainerProtocolProvider.Server(container));
- }
- }
-
- protected void processConnector(IManagedContainer container, String factoryType, String description,
- InternalConnector connector)
- {
- ITransportConfig config = connector.getConfig();
- if (config.getBufferProvider() == null)
- {
- config.setBufferProvider(getBufferProvider(container));
- }
-
- if (config.getReceiveExecutor() == null)
- {
- config.setReceiveExecutor(getExecutorService(container));
- }
-
- if (config.getProtocolProvider() == null)
- {
- config.setProtocolProvider(new ContainerProtocolProvider.Client(container));
- }
- }
-
- /**
- * @since 2.0
- */
- protected IBufferProvider getBufferProvider(IManagedContainer container)
- {
- return (IBufferProvider)container.getElement(BufferProviderFactory.PRODUCT_GROUP, BufferProviderFactory.TYPE, null);
- }
-
- protected ExecutorService getExecutorService(IManagedContainer container)
- {
- return (ExecutorService)container.getElement(ExecutorServiceFactory.PRODUCT_GROUP, ExecutorServiceFactory.TYPE,
- null);
- }
-}
+/*
+ * 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;
+
+import org.eclipse.net4j.acceptor.IAcceptor;
+import org.eclipse.net4j.buffer.IBufferProvider;
+import org.eclipse.net4j.connector.IConnector;
+import org.eclipse.net4j.util.concurrent.ExecutorServiceFactory;
+import org.eclipse.net4j.util.container.IElementProcessor;
+import org.eclipse.net4j.util.container.IManagedContainer;
+
+import org.eclipse.internal.net4j.buffer.BufferProviderFactory;
+
+import org.eclipse.spi.net4j.InternalAcceptor;
+import org.eclipse.spi.net4j.InternalConnector;
+
+import java.util.concurrent.ExecutorService;
+
+/**
+ * An element post processor that injects a {@link ITransportConfig transport configuration} into the {@link IConnector
+ * connectors} and {@link IAcceptor acceptors} of a {@link IManagedContainer managed container}.
+ *
+ * @author Eike Stepper
+ * @since 2.0
+ */
+public class TransportInjector implements IElementProcessor
+{
+ public TransportInjector()
+ {
+ }
+
+ public Object process(IManagedContainer container, String productGroup, String factoryType, String description,
+ Object element)
+ {
+ if (element instanceof InternalAcceptor)
+ {
+ InternalAcceptor acceptor = (InternalAcceptor)element;
+ processAcceptor(container, factoryType, description, acceptor);
+ }
+ else if (element instanceof InternalConnector)
+ {
+ InternalConnector connector = (InternalConnector)element;
+ processConnector(container, factoryType, description, connector);
+ }
+
+ return element;
+ }
+
+ protected void processAcceptor(IManagedContainer container, String factoryType, String description,
+ InternalAcceptor acceptor)
+ {
+ ITransportConfig config = acceptor.getConfig();
+ if (config.getBufferProvider() == null)
+ {
+ config.setBufferProvider(getBufferProvider(container));
+ }
+
+ if (config.getReceiveExecutor() == null)
+ {
+ config.setReceiveExecutor(getExecutorService(container));
+ }
+
+ if (config.getProtocolProvider() == null)
+ {
+ config.setProtocolProvider(new ContainerProtocolProvider.Server(container));
+ }
+ }
+
+ protected void processConnector(IManagedContainer container, String factoryType, String description,
+ InternalConnector connector)
+ {
+ ITransportConfig config = connector.getConfig();
+ if (config.getBufferProvider() == null)
+ {
+ config.setBufferProvider(getBufferProvider(container));
+ }
+
+ if (config.getReceiveExecutor() == null)
+ {
+ config.setReceiveExecutor(getExecutorService(container));
+ }
+
+ if (config.getProtocolProvider() == null)
+ {
+ config.setProtocolProvider(new ContainerProtocolProvider.Client(container));
+ }
+ }
+
+ /**
+ * @since 2.0
+ */
+ protected IBufferProvider getBufferProvider(IManagedContainer container)
+ {
+ return (IBufferProvider)container.getElement(BufferProviderFactory.PRODUCT_GROUP, BufferProviderFactory.TYPE, null);
+ }
+
+ protected ExecutorService getExecutorService(IManagedContainer container)
+ {
+ return (ExecutorService)container.getElement(ExecutorServiceFactory.PRODUCT_GROUP, ExecutorServiceFactory.TYPE,
+ null);
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/acceptor/IAcceptor.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/acceptor/IAcceptor.java
index 7e615f61d1..a4b9d7d01f 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/acceptor/IAcceptor.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/acceptor/IAcceptor.java
@@ -1,53 +1,53 @@
-/*
- * 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.acceptor;
-
-import org.eclipse.net4j.ILocationAware.Location;
-import org.eclipse.net4j.connector.IConnector;
-import org.eclipse.net4j.util.collection.Closeable;
-import org.eclipse.net4j.util.container.IContainer;
-
-import org.eclipse.spi.net4j.Acceptor;
-
-/**
- * Accepts incoming connection requests from {@link Location#CLIENT client} {@link IConnector connectors} and creates
- * the appropriate {@link Location#SERVER server} connectors.
- * <p>
- * Since the process of accepting connection requests is heavily dependent on the implementation of the respective
- * connectors the only public API is introspection and notification.
- * <p>
- * This interface is <b>not</b> intended to be implemented by clients. Service providers <b>must</b> extend the abstract
- * {@link Acceptor} class.
- * <p>
- * <dt><b>Class Diagram:</b></dt>
- * <dd><img src="doc-files/IAcceptor-1.gif" title="Diagram Acceptors" border="0" usemap="#IAcceptor-1.gif"/></dd>
- * <p>
- * <MAP NAME="IAcceptor-1.gif"> <AREA SHAPE="RECT" COORDS="10,8,99,58" HREF="IAcceptor.html"> <AREA SHAPE="RECT"
- * COORDS="289,8,378,58" HREF="../connector/IConnector.html"> </MAP>
- * <p>
- * <dt><b>Sequence Diagram:</b></dt>
- * <dd><img src="doc-files/IAcceptor-2.gif" title="Connection Process" border="0" usemap="#IAcceptor-2.gif"/></dd>
- * <p>
- * <MAP NAME="IAcceptor-2.gif"> <AREA SHAPE="RECT" COORDS="146,136,265,165" HREF="IConnector.html"> <AREA SHAPE="RECT"
- * COORDS="485,75,564,105" HREF="IAcceptor.html"> <AREA SHAPE="RECT" COORDS="296,325,414,355" HREF="IConnector.html">
- * <AREA SHAPE="RECT" COORDS="64,426,444,506" HREF="ConnectorState.html#CONNECTING"> <AREA SHAPE="RECT"
- * COORDS="64,516,444,596" HREF="ConnectorState.html#NEGOTIATING"> </MAP>
- *
- * @author Eike Stepper
- * @noimplement This interface is not intended to be implemented by clients.
- */
-public interface IAcceptor extends IContainer<IConnector>, Closeable
-{
- /**
- * Returns an array of the connectors that have been accepted by this acceptor and not been closed since.
- */
- public IConnector[] getAcceptedConnectors();
-}
+/*
+ * 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.acceptor;
+
+import org.eclipse.net4j.ILocationAware.Location;
+import org.eclipse.net4j.connector.IConnector;
+import org.eclipse.net4j.util.collection.Closeable;
+import org.eclipse.net4j.util.container.IContainer;
+
+import org.eclipse.spi.net4j.Acceptor;
+
+/**
+ * Accepts incoming connection requests from {@link Location#CLIENT client} {@link IConnector connectors} and creates
+ * the appropriate {@link Location#SERVER server} connectors.
+ * <p>
+ * Since the process of accepting connection requests is heavily dependent on the implementation of the respective
+ * connectors the only public API is introspection and notification.
+ * <p>
+ * This interface is <b>not</b> intended to be implemented by clients. Service providers <b>must</b> extend the abstract
+ * {@link Acceptor} class.
+ * <p>
+ * <dt><b>Class Diagram:</b></dt>
+ * <dd><img src="doc-files/IAcceptor-1.gif" title="Diagram Acceptors" border="0" usemap="#IAcceptor-1.gif"/></dd>
+ * <p>
+ * <MAP NAME="IAcceptor-1.gif"> <AREA SHAPE="RECT" COORDS="10,8,99,58" HREF="IAcceptor.html"> <AREA SHAPE="RECT"
+ * COORDS="289,8,378,58" HREF="../connector/IConnector.html"> </MAP>
+ * <p>
+ * <dt><b>Sequence Diagram:</b></dt>
+ * <dd><img src="doc-files/IAcceptor-2.gif" title="Connection Process" border="0" usemap="#IAcceptor-2.gif"/></dd>
+ * <p>
+ * <MAP NAME="IAcceptor-2.gif"> <AREA SHAPE="RECT" COORDS="146,136,265,165" HREF="IConnector.html"> <AREA SHAPE="RECT"
+ * COORDS="485,75,564,105" HREF="IAcceptor.html"> <AREA SHAPE="RECT" COORDS="296,325,414,355" HREF="IConnector.html">
+ * <AREA SHAPE="RECT" COORDS="64,426,444,506" HREF="ConnectorState.html#CONNECTING"> <AREA SHAPE="RECT"
+ * COORDS="64,516,444,596" HREF="ConnectorState.html#NEGOTIATING"> </MAP>
+ *
+ * @author Eike Stepper
+ * @noimplement This interface is not intended to be implemented by clients.
+ */
+public interface IAcceptor extends IContainer<IConnector>, Closeable
+{
+ /**
+ * Returns an array of the connectors that have been accepted by this acceptor and not been closed since.
+ */
+ public IConnector[] getAcceptedConnectors();
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/acceptor/package-info.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/acceptor/package-info.java
index afba085e61..4d3df6c7bd 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/acceptor/package-info.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/acceptor/package-info.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
+ * 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
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/buffer/BufferInputStream.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/buffer/BufferInputStream.java
index 9dcadfe760..e806d3930b 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/buffer/BufferInputStream.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/buffer/BufferInputStream.java
@@ -1,229 +1,229 @@
-/*
- * 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.buffer;
-
-import org.eclipse.net4j.signal.RemoteException;
-import org.eclipse.net4j.util.HexUtil;
-import org.eclipse.net4j.util.WrappedException;
-import org.eclipse.net4j.util.io.IOTimeoutException;
-import org.eclipse.net4j.util.io.IOUtil;
-import org.eclipse.net4j.util.om.trace.ContextTracer;
-
-import org.eclipse.internal.net4j.bundle.OM;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.nio.ByteBuffer;
-import java.util.concurrent.BlockingQueue;
-import java.util.concurrent.LinkedBlockingQueue;
-import java.util.concurrent.TimeUnit;
-
-/**
- * A {@link IBufferHandler buffer handler} that defragments the passed {@link IBuffer buffers} into a continuous byte
- * sequence which is exposed as an {@link InputStream input stream}.
- *
- * @author Eike Stepper
- */
-public class BufferInputStream extends InputStream implements IBufferHandler
-{
- public static final long NO_TIMEOUT = -1;
-
- public static final long DEFAULT_MILLIS_BEFORE_TIMEOUT = NO_TIMEOUT;
-
- public static final long DEFAULT_MILLIS_INTERRUPT_CHECK = 100;
-
- private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_BUFFER_STREAM, BufferInputStream.class);
-
- private final boolean tracerEnabled;
-
- private BlockingQueue<IBuffer> buffers = new LinkedBlockingQueue<IBuffer>();
-
- private IBuffer currentBuffer;
-
- private boolean eos;
-
- private RemoteException exception;
-
- private long stopTimeMillis;
-
- public BufferInputStream()
- {
- tracerEnabled = TRACER.isEnabled();
- }
-
- public long getMillisBeforeTimeout()
- {
- return DEFAULT_MILLIS_BEFORE_TIMEOUT;
- }
-
- public long getMillisInterruptCheck()
- {
- return DEFAULT_MILLIS_INTERRUPT_CHECK;
- }
-
- /**
- * @since 2.0
- */
- public void restartTimeout()
- {
- synchronized (this)
- {
- stopTimeMillis = System.currentTimeMillis() + getMillisBeforeTimeout();
- }
- }
-
- /**
- * @since 2.0
- */
- public RuntimeException getException()
- {
- return exception;
- }
-
- /**
- * @since 4.0
- */
- public void setException(RemoteException exception)
- {
- this.exception = exception;
- }
-
- public void handleBuffer(IBuffer buffer)
- {
- buffers.add(buffer);
- }
-
- @SuppressWarnings("deprecation")
- @Override
- public int read() throws IOException
- {
- if (currentBuffer == null)
- {
- if (eos)
- {
- // End of stream
- return IOUtil.EOF;
- }
-
- if (!ensureBuffer())
- {
- // Timeout or interrupt
- return IOUtil.EOF;
- }
- }
-
- ByteBuffer byteBuffer = currentBuffer.getByteBuffer();
- if (!byteBuffer.hasRemaining())
- {
- // End of stream
- return IOUtil.EOF;
- }
-
- final int result = byteBuffer.get() & 0xFF;
- if (tracerEnabled)
- {
- TRACER.trace("<-- " + HexUtil.formatByte(result) //$NON-NLS-1$
- + (result >= 32 ? " " + Character.toString((char)result) : "")); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- if (!byteBuffer.hasRemaining())
- {
- currentBuffer.release();
- currentBuffer = null;
- }
-
- return result;
- }
-
- @Override
- public void close() throws IOException
- {
- buffers = null;
- currentBuffer = null;
- super.close();
- }
-
- @Override
- public String toString()
- {
- return "BufferInputStream"; //$NON-NLS-1$
- }
-
- protected boolean ensureBuffer() throws IOException
- {
- final long check = getMillisInterruptCheck();
-
- try
- {
- if (getMillisBeforeTimeout() == NO_TIMEOUT)
- {
- while (currentBuffer == null)
- {
- throwRemoteExceptionIfExists();
-
- if (buffers == null)
- {
- // Stream has been closed - shutting down
- return false;
- }
-
- currentBuffer = buffers.poll(check, TimeUnit.MILLISECONDS);
- }
- }
- else
- {
- restartTimeout();
- while (currentBuffer == null)
- {
- throwRemoteExceptionIfExists();
-
- if (buffers == null)
- {
- // Stream has been closed - shutting down
- return false;
- }
-
- long remaining;
- synchronized (this)
- {
- remaining = stopTimeMillis;
- }
-
- remaining -= System.currentTimeMillis();
- if (remaining <= 0)
- {
- // Throw an exception so that caller can distinguish between end-of-stream and a timeout
- throw new IOTimeoutException();
- }
-
- currentBuffer = buffers.poll(Math.min(remaining, check), TimeUnit.MILLISECONDS);
- }
- }
- }
- catch (InterruptedException ex)
- {
- throw WrappedException.wrap(ex);
- }
-
- eos = currentBuffer.isEOS();
- return true;
- }
-
- private void throwRemoteExceptionIfExists()
- {
- if (exception != null)
- {
- StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
- exception.setLocalStacktrace(stackTrace);
- 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.buffer;
+
+import org.eclipse.net4j.signal.RemoteException;
+import org.eclipse.net4j.util.HexUtil;
+import org.eclipse.net4j.util.WrappedException;
+import org.eclipse.net4j.util.io.IOTimeoutException;
+import org.eclipse.net4j.util.io.IOUtil;
+import org.eclipse.net4j.util.om.trace.ContextTracer;
+
+import org.eclipse.internal.net4j.bundle.OM;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.ByteBuffer;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * A {@link IBufferHandler buffer handler} that defragments the passed {@link IBuffer buffers} into a continuous byte
+ * sequence which is exposed as an {@link InputStream input stream}.
+ *
+ * @author Eike Stepper
+ */
+public class BufferInputStream extends InputStream implements IBufferHandler
+{
+ public static final long NO_TIMEOUT = -1;
+
+ public static final long DEFAULT_MILLIS_BEFORE_TIMEOUT = NO_TIMEOUT;
+
+ public static final long DEFAULT_MILLIS_INTERRUPT_CHECK = 100;
+
+ private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_BUFFER_STREAM, BufferInputStream.class);
+
+ private final boolean tracerEnabled;
+
+ private BlockingQueue<IBuffer> buffers = new LinkedBlockingQueue<IBuffer>();
+
+ private IBuffer currentBuffer;
+
+ private boolean eos;
+
+ private RemoteException exception;
+
+ private long stopTimeMillis;
+
+ public BufferInputStream()
+ {
+ tracerEnabled = TRACER.isEnabled();
+ }
+
+ public long getMillisBeforeTimeout()
+ {
+ return DEFAULT_MILLIS_BEFORE_TIMEOUT;
+ }
+
+ public long getMillisInterruptCheck()
+ {
+ return DEFAULT_MILLIS_INTERRUPT_CHECK;
+ }
+
+ /**
+ * @since 2.0
+ */
+ public void restartTimeout()
+ {
+ synchronized (this)
+ {
+ stopTimeMillis = System.currentTimeMillis() + getMillisBeforeTimeout();
+ }
+ }
+
+ /**
+ * @since 2.0
+ */
+ public RuntimeException getException()
+ {
+ return exception;
+ }
+
+ /**
+ * @since 4.0
+ */
+ public void setException(RemoteException exception)
+ {
+ this.exception = exception;
+ }
+
+ public void handleBuffer(IBuffer buffer)
+ {
+ buffers.add(buffer);
+ }
+
+ @SuppressWarnings("deprecation")
+ @Override
+ public int read() throws IOException
+ {
+ if (currentBuffer == null)
+ {
+ if (eos)
+ {
+ // End of stream
+ return IOUtil.EOF;
+ }
+
+ if (!ensureBuffer())
+ {
+ // Timeout or interrupt
+ return IOUtil.EOF;
+ }
+ }
+
+ ByteBuffer byteBuffer = currentBuffer.getByteBuffer();
+ if (!byteBuffer.hasRemaining())
+ {
+ // End of stream
+ return IOUtil.EOF;
+ }
+
+ final int result = byteBuffer.get() & 0xFF;
+ if (tracerEnabled)
+ {
+ TRACER.trace("<-- " + HexUtil.formatByte(result) //$NON-NLS-1$
+ + (result >= 32 ? " " + Character.toString((char)result) : "")); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ if (!byteBuffer.hasRemaining())
+ {
+ currentBuffer.release();
+ currentBuffer = null;
+ }
+
+ return result;
+ }
+
+ @Override
+ public void close() throws IOException
+ {
+ buffers = null;
+ currentBuffer = null;
+ super.close();
+ }
+
+ @Override
+ public String toString()
+ {
+ return "BufferInputStream"; //$NON-NLS-1$
+ }
+
+ protected boolean ensureBuffer() throws IOException
+ {
+ final long check = getMillisInterruptCheck();
+
+ try
+ {
+ if (getMillisBeforeTimeout() == NO_TIMEOUT)
+ {
+ while (currentBuffer == null)
+ {
+ throwRemoteExceptionIfExists();
+
+ if (buffers == null)
+ {
+ // Stream has been closed - shutting down
+ return false;
+ }
+
+ currentBuffer = buffers.poll(check, TimeUnit.MILLISECONDS);
+ }
+ }
+ else
+ {
+ restartTimeout();
+ while (currentBuffer == null)
+ {
+ throwRemoteExceptionIfExists();
+
+ if (buffers == null)
+ {
+ // Stream has been closed - shutting down
+ return false;
+ }
+
+ long remaining;
+ synchronized (this)
+ {
+ remaining = stopTimeMillis;
+ }
+
+ remaining -= System.currentTimeMillis();
+ if (remaining <= 0)
+ {
+ // Throw an exception so that caller can distinguish between end-of-stream and a timeout
+ throw new IOTimeoutException();
+ }
+
+ currentBuffer = buffers.poll(Math.min(remaining, check), TimeUnit.MILLISECONDS);
+ }
+ }
+ }
+ catch (InterruptedException ex)
+ {
+ throw WrappedException.wrap(ex);
+ }
+
+ eos = currentBuffer.isEOS();
+ return true;
+ }
+
+ private void throwRemoteExceptionIfExists()
+ {
+ if (exception != null)
+ {
+ StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
+ exception.setLocalStacktrace(stackTrace);
+ throw exception;
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/buffer/BufferOutputStream.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/buffer/BufferOutputStream.java
index aa83505e19..276f25cf23 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/buffer/BufferOutputStream.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/buffer/BufferOutputStream.java
@@ -1,254 +1,254 @@
-/*
- * 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
- * Andre Dietisheim - Bug 262875: java.nio.BufferUnderFlowException https://bugs.eclipse.org/bugs/show_bug.cgi?id=262875
- */
-package org.eclipse.net4j.buffer;
-
-import org.eclipse.net4j.util.HexUtil;
-import org.eclipse.net4j.util.IErrorHandler;
-import org.eclipse.net4j.util.ReflectUtil.ExcludeFromDump;
-import org.eclipse.net4j.util.io.IORuntimeException;
-import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
-import org.eclipse.net4j.util.om.trace.ContextTracer;
-
-import org.eclipse.internal.net4j.bundle.OM;
-
-import java.io.IOException;
-import java.io.OutputStream;
-import java.nio.ByteBuffer;
-
-/**
- * An {@link OutputStream output stream} that fragments the written byte sequence into fixed-sized {@link IBuffer
- * buffers} and passes them to configured {@link IBufferHandler buffer handler}.
- *
- * @author Eike Stepper
- */
-public class BufferOutputStream extends OutputStream
-{
- public static final boolean DEFAULT_PROPAGATE_CLOSE = false;
-
- private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_BUFFER_STREAM, BufferOutputStream.class);
-
- private final boolean tracerEnabled;
-
- private IBufferProvider bufferProvider;
-
- private IBufferHandler bufferHandler;
-
- private IBuffer currentBuffer;
-
- private short channelID;
-
- private Throwable error;
-
- @ExcludeFromDump
- private transient IErrorHandler errorHandler = new IErrorHandler()
- {
- public void handleError(Throwable t)
- {
- setError(t);
- }
- };
-
- public BufferOutputStream(IBufferHandler bufferHandler, IBufferProvider bufferProvider, short channelID)
- {
- if (bufferHandler == null)
- {
- throw new IllegalArgumentException("bufferHandler == null"); //$NON-NLS-1$
- }
-
- if (bufferProvider == null)
- {
- throw new IllegalArgumentException("bufferProvider == null"); //$NON-NLS-1$
- }
-
- this.bufferHandler = bufferHandler;
- this.bufferProvider = bufferProvider;
- this.channelID = channelID;
- tracerEnabled = TRACER.isEnabled();
- }
-
- public BufferOutputStream(IBufferHandler bufferHandler, short channelID)
- {
- this(bufferHandler, extractBufferProvider(bufferHandler), channelID);
- }
-
- /**
- * @since 2.0
- */
- public Throwable getError()
- {
- return error;
- }
-
- /**
- * @since 2.0
- */
- public void setError(Throwable error)
- {
- this.error = error;
- }
-
- @SuppressWarnings("deprecation")
- @Override
- public void write(int b) throws IOException
- {
- throwExceptionOnError();
- flushIfFilled();
- ensureBufferPrivate();
-
- // If this was called with a primitive byte with a negative value,
- // the implicit conversion prepended 24 leading 1's. We'll undo those.
- b = b & 0xFF;
-
- if (tracerEnabled)
- {
- TRACER.trace("--> " + HexUtil.formatByte(b) //$NON-NLS-1$
- + (b >= 32 ? " " + Character.toString((char)b) : "")); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- ByteBuffer buffer = currentBuffer.getByteBuffer();
- buffer.put((byte)b);
- }
-
- /**
- * Flushes the current buffer, it's handled over to the buffer handler.
- *
- * @throws IOException
- * Signals that an I/O exception has occurred.
- * @see #currentBuffer
- * @see IBufferHandler#handleBuffer(IBuffer)
- */
- @Override
- public void flush() throws IOException
- {
- flushPrivate();
- }
-
- /**
- * Flushes the current buffer if it has no remaining space.
- *
- * @throws IOException
- * Signals that an I/O exception has occurred.
- */
- private void flushIfFilled() throws IOException
- {
- if (currentBuffer != null && !currentBuffer.getByteBuffer().hasRemaining())
- {
- flushPrivate();
- }
- }
-
- private void flushPrivate()
- {
- if (currentBuffer != null)
- {
- bufferHandler.handleBuffer(currentBuffer);
- currentBuffer = null;
- }
- }
-
- public void flushWithEOS() throws IOException
- {
- throwExceptionOnError();
- ensureBufferPrivate();
- currentBuffer.setEOS(true);
- flushPrivate();
- }
-
- @Override
- public void close() throws IOException
- {
- try
- {
- if (isPropagateClose())
- {
- LifecycleUtil.deactivate(bufferHandler);
- }
- }
- finally
- {
- bufferHandler = null;
- bufferProvider = null;
- currentBuffer = null;
- super.close();
- }
- }
-
- @Override
- public String toString()
- {
- return "BufferOutputStream"; //$NON-NLS-1$
- }
-
- /**
- * Ensures that this BufferOutputStream has a buffer. If the current buffer was flushed a new one is fetched from the
- * buffer provider.
- *
- * @throws IOException
- * Signals that an I/O exception has occurred.
- * @see #flush()
- * @see IBufferProvider#provideBuffer()
- */
- protected void ensureBuffer() throws IOException
- {
- ensureBufferPrivate();
- }
-
- private void ensureBufferPrivate()
- {
- if (currentBuffer == null)
- {
- currentBuffer = bufferProvider.provideBuffer();
- currentBuffer.setErrorHandler(errorHandler);
- currentBuffer.startPutting(channelID);
- }
- }
-
- /**
- * Throws an exception if there's an error.
- *
- * @throws IOException
- * Signals that an I/O exception has occurred.
- * @see #error
- */
- private void throwExceptionOnError() throws IOException
- {
- if (error != null)
- {
- if (error instanceof IOException)
- {
- throw (IOException)error;
- }
-
- if (error instanceof RuntimeException)
- {
- throw (RuntimeException)error;
- }
-
- throw new IORuntimeException(error);
- }
- }
-
- protected boolean isPropagateClose()
- {
- return DEFAULT_PROPAGATE_CLOSE;
- }
-
- private static IBufferProvider extractBufferProvider(IBufferHandler bufferHandler)
- {
- if (bufferHandler instanceof IBufferProvider)
- {
- return (IBufferProvider)bufferHandler;
- }
-
- throw new IllegalArgumentException("Buffer handler unable to provide buffers"); //$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
+ * Andre Dietisheim - Bug 262875: java.nio.BufferUnderFlowException https://bugs.eclipse.org/bugs/show_bug.cgi?id=262875
+ */
+package org.eclipse.net4j.buffer;
+
+import org.eclipse.net4j.util.HexUtil;
+import org.eclipse.net4j.util.IErrorHandler;
+import org.eclipse.net4j.util.ReflectUtil.ExcludeFromDump;
+import org.eclipse.net4j.util.io.IORuntimeException;
+import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
+import org.eclipse.net4j.util.om.trace.ContextTracer;
+
+import org.eclipse.internal.net4j.bundle.OM;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.nio.ByteBuffer;
+
+/**
+ * An {@link OutputStream output stream} that fragments the written byte sequence into fixed-sized {@link IBuffer
+ * buffers} and passes them to configured {@link IBufferHandler buffer handler}.
+ *
+ * @author Eike Stepper
+ */
+public class BufferOutputStream extends OutputStream
+{
+ public static final boolean DEFAULT_PROPAGATE_CLOSE = false;
+
+ private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_BUFFER_STREAM, BufferOutputStream.class);
+
+ private final boolean tracerEnabled;
+
+ private IBufferProvider bufferProvider;
+
+ private IBufferHandler bufferHandler;
+
+ private IBuffer currentBuffer;
+
+ private short channelID;
+
+ private Throwable error;
+
+ @ExcludeFromDump
+ private transient IErrorHandler errorHandler = new IErrorHandler()
+ {
+ public void handleError(Throwable t)
+ {
+ setError(t);
+ }
+ };
+
+ public BufferOutputStream(IBufferHandler bufferHandler, IBufferProvider bufferProvider, short channelID)
+ {
+ if (bufferHandler == null)
+ {
+ throw new IllegalArgumentException("bufferHandler == null"); //$NON-NLS-1$
+ }
+
+ if (bufferProvider == null)
+ {
+ throw new IllegalArgumentException("bufferProvider == null"); //$NON-NLS-1$
+ }
+
+ this.bufferHandler = bufferHandler;
+ this.bufferProvider = bufferProvider;
+ this.channelID = channelID;
+ tracerEnabled = TRACER.isEnabled();
+ }
+
+ public BufferOutputStream(IBufferHandler bufferHandler, short channelID)
+ {
+ this(bufferHandler, extractBufferProvider(bufferHandler), channelID);
+ }
+
+ /**
+ * @since 2.0
+ */
+ public Throwable getError()
+ {
+ return error;
+ }
+
+ /**
+ * @since 2.0
+ */
+ public void setError(Throwable error)
+ {
+ this.error = error;
+ }
+
+ @SuppressWarnings("deprecation")
+ @Override
+ public void write(int b) throws IOException
+ {
+ throwExceptionOnError();
+ flushIfFilled();
+ ensureBufferPrivate();
+
+ // If this was called with a primitive byte with a negative value,
+ // the implicit conversion prepended 24 leading 1's. We'll undo those.
+ b = b & 0xFF;
+
+ if (tracerEnabled)
+ {
+ TRACER.trace("--> " + HexUtil.formatByte(b) //$NON-NLS-1$
+ + (b >= 32 ? " " + Character.toString((char)b) : "")); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ ByteBuffer buffer = currentBuffer.getByteBuffer();
+ buffer.put((byte)b);
+ }
+
+ /**
+ * Flushes the current buffer, it's handled over to the buffer handler.
+ *
+ * @throws IOException
+ * Signals that an I/O exception has occurred.
+ * @see #currentBuffer
+ * @see IBufferHandler#handleBuffer(IBuffer)
+ */
+ @Override
+ public void flush() throws IOException
+ {
+ flushPrivate();
+ }
+
+ /**
+ * Flushes the current buffer if it has no remaining space.
+ *
+ * @throws IOException
+ * Signals that an I/O exception has occurred.
+ */
+ private void flushIfFilled() throws IOException
+ {
+ if (currentBuffer != null && !currentBuffer.getByteBuffer().hasRemaining())
+ {
+ flushPrivate();
+ }
+ }
+
+ private void flushPrivate()
+ {
+ if (currentBuffer != null)
+ {
+ bufferHandler.handleBuffer(currentBuffer);
+ currentBuffer = null;
+ }
+ }
+
+ public void flushWithEOS() throws IOException
+ {
+ throwExceptionOnError();
+ ensureBufferPrivate();
+ currentBuffer.setEOS(true);
+ flushPrivate();
+ }
+
+ @Override
+ public void close() throws IOException
+ {
+ try
+ {
+ if (isPropagateClose())
+ {
+ LifecycleUtil.deactivate(bufferHandler);
+ }
+ }
+ finally
+ {
+ bufferHandler = null;
+ bufferProvider = null;
+ currentBuffer = null;
+ super.close();
+ }
+ }
+
+ @Override
+ public String toString()
+ {
+ return "BufferOutputStream"; //$NON-NLS-1$
+ }
+
+ /**
+ * Ensures that this BufferOutputStream has a buffer. If the current buffer was flushed a new one is fetched from the
+ * buffer provider.
+ *
+ * @throws IOException
+ * Signals that an I/O exception has occurred.
+ * @see #flush()
+ * @see IBufferProvider#provideBuffer()
+ */
+ protected void ensureBuffer() throws IOException
+ {
+ ensureBufferPrivate();
+ }
+
+ private void ensureBufferPrivate()
+ {
+ if (currentBuffer == null)
+ {
+ currentBuffer = bufferProvider.provideBuffer();
+ currentBuffer.setErrorHandler(errorHandler);
+ currentBuffer.startPutting(channelID);
+ }
+ }
+
+ /**
+ * Throws an exception if there's an error.
+ *
+ * @throws IOException
+ * Signals that an I/O exception has occurred.
+ * @see #error
+ */
+ private void throwExceptionOnError() throws IOException
+ {
+ if (error != null)
+ {
+ if (error instanceof IOException)
+ {
+ throw (IOException)error;
+ }
+
+ if (error instanceof RuntimeException)
+ {
+ throw (RuntimeException)error;
+ }
+
+ throw new IORuntimeException(error);
+ }
+ }
+
+ protected boolean isPropagateClose()
+ {
+ return DEFAULT_PROPAGATE_CLOSE;
+ }
+
+ private static IBufferProvider extractBufferProvider(IBufferHandler bufferHandler)
+ {
+ if (bufferHandler instanceof IBufferProvider)
+ {
+ return (IBufferProvider)bufferHandler;
+ }
+
+ throw new IllegalArgumentException("Buffer handler unable to provide buffers"); //$NON-NLS-1$
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/buffer/BufferState.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/buffer/BufferState.java
index 5e0f8183ab..3e04f5aa26 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/buffer/BufferState.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/buffer/BufferState.java
@@ -1,110 +1,110 @@
-/*
- * 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.buffer;
-
-import java.nio.ByteBuffer;
-import java.nio.channels.SocketChannel;
-
-/**
- * Enumerates the internal states of an {@link IBuffer}.
- * <p>
- * <dt><b>State Machine Diagram:</b></dt>
- * <dd><img src="doc-files/BufferState-1.gif" title="Diagram Buffer States" border="0" usemap="#BufferState-1.gif"/></dd>
- * <p>
- * <MAP NAME="BufferState-1.gif"> <AREA SHAPE="RECT" COORDS="300,8,449,34" HREF="BufferState.html#INITIAL"> <AREA
- * SHAPE="RECT" COORDS="46,115,195,139" HREF="BufferState.html#PUTTING"> <AREA SHAPE="RECT" COORDS="48,271,195,295"
- * HREF="BufferState.html#WRITING"> <AREA SHAPE="RECT" COORDS="533,112,681,140" HREF="BufferState.html#READING_HEADER">
- * <AREA SHAPE="RECT" COORDS="533,271,680,295" HREF="BufferState.html#READING_BODY"> <AREA SHAPE="RECT"
- * COORDS="532,428,682,451" HREF="BufferState.html#GETTING"> </MAP>
- *
- * @author Eike Stepper
- * @noextend This interface is not intended to be extended by clients.
- */
-public enum BufferState
-{
- /**
- * Indicates that the {@link IBuffer} has just been provided by its {@link IBufferProvider} or that is has been used
- * and subsequently {@link IBuffer#clear() cleared}.
- * <p>
- * A transition to {@link #PUTTING} can be triggered by calling {@link IBuffer#startPutting(short)} once. If the
- * buffer is intended to be passed to an {@link org.eclipse.net4j.channel.IChannel IChannel} later the
- * {@link org.eclipse.net4j.channel.IChannel#getID() channel index} of that Channel has to be passed because it is
- * part of the buffer's header. A {@link ByteBuffer} is returned that can be used for putting data.
- * <p>
- * A transition to {@link #GETTING} can be triggered by calling {@link IBuffer#startGetting(SocketChannel)} repeatedly
- * until it finally returns a {@link ByteBuffer} that can be used for getting data.
- */
- INITIAL,
-
- /**
- * Indicates that the {@link IBuffer} can provide a {@link ByteBuffer} that can be used for putting data.
- * <p>
- * A transition to {@link #WRITING} can be triggered by calling {@link IBuffer#write(SocketChannel)}.
- * <p>
- * A transition to {@link #GETTING} can be triggered by calling {@link IBuffer#flip()}.
- * <p>
- * A transition to {@link #INITIAL} can be triggered by calling {@link IBuffer#clear()}.
- */
- PUTTING,
-
- /**
- * Indicates that the {@link IBuffer} is currently writing its data to a {@link SocketChannel}.
- * <p>
- * Self transitions to {@link #WRITING} can be triggered by repeatedly calling {@link IBuffer#write(SocketChannel)}
- * until it returns <code>true</code>.
- * <p>
- * A transition to {@link #INITIAL} can be triggered by calling {@link IBuffer#clear()}.
- */
- WRITING,
-
- /**
- * Indicates that the {@link IBuffer} is currently reading its header from a {@link SocketChannel}.
- * <p>
- * Transitions to {@link #READING_HEADER}, {@link #READING_BODY} or {@link #GETTING} can be triggered by repeatedly
- * calling {@link IBuffer#startGetting(SocketChannel)} until it returns a {@link ByteBuffer} that can be used for
- * getting data.
- * <p>
- * A transition to {@link #INITIAL} can be triggered by calling {@link IBuffer#clear()}.
- */
- READING_HEADER,
-
- /**
- * Indicates that the {@link IBuffer} is currently reading its body from a {@link SocketChannel}.
- * <p>
- * Transitions to {@link #READING_BODY} or {@link #GETTING} can be triggered by repeatedly calling
- * {@link IBuffer#startGetting(SocketChannel)} until it returns a {@link ByteBuffer} that can be used for getting
- * data.
- * <p>
- * A transition to {@link #INITIAL} can be triggered by calling {@link IBuffer#clear()}.
- */
- READING_BODY,
-
- /**
- * Indicates that the {@link IBuffer} can provide a {@link ByteBuffer} that can be used for getting data.
- * <p>
- * A transition to {@link #INITIAL} can be triggered by calling {@link IBuffer#clear()}.
- */
- GETTING,
-
- /**
- * Indicates that the {@link IBuffer} is owned by its {@link IBufferProvider}.
- *
- * @since 3.0
- */
- RELEASED,
-
- /**
- * Indicates that the {@link IBuffer} can not be used anymore.
- *
- * @since 3.0
- */
- DISPOSED
-}
+/*
+ * 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.buffer;
+
+import java.nio.ByteBuffer;
+import java.nio.channels.SocketChannel;
+
+/**
+ * Enumerates the internal states of an {@link IBuffer}.
+ * <p>
+ * <dt><b>State Machine Diagram:</b></dt>
+ * <dd><img src="doc-files/BufferState-1.gif" title="Diagram Buffer States" border="0" usemap="#BufferState-1.gif"/></dd>
+ * <p>
+ * <MAP NAME="BufferState-1.gif"> <AREA SHAPE="RECT" COORDS="300,8,449,34" HREF="BufferState.html#INITIAL"> <AREA
+ * SHAPE="RECT" COORDS="46,115,195,139" HREF="BufferState.html#PUTTING"> <AREA SHAPE="RECT" COORDS="48,271,195,295"
+ * HREF="BufferState.html#WRITING"> <AREA SHAPE="RECT" COORDS="533,112,681,140" HREF="BufferState.html#READING_HEADER">
+ * <AREA SHAPE="RECT" COORDS="533,271,680,295" HREF="BufferState.html#READING_BODY"> <AREA SHAPE="RECT"
+ * COORDS="532,428,682,451" HREF="BufferState.html#GETTING"> </MAP>
+ *
+ * @author Eike Stepper
+ * @noextend This interface is not intended to be extended by clients.
+ */
+public enum BufferState
+{
+ /**
+ * Indicates that the {@link IBuffer} has just been provided by its {@link IBufferProvider} or that is has been used
+ * and subsequently {@link IBuffer#clear() cleared}.
+ * <p>
+ * A transition to {@link #PUTTING} can be triggered by calling {@link IBuffer#startPutting(short)} once. If the
+ * buffer is intended to be passed to an {@link org.eclipse.net4j.channel.IChannel IChannel} later the
+ * {@link org.eclipse.net4j.channel.IChannel#getID() channel index} of that Channel has to be passed because it is
+ * part of the buffer's header. A {@link ByteBuffer} is returned that can be used for putting data.
+ * <p>
+ * A transition to {@link #GETTING} can be triggered by calling {@link IBuffer#startGetting(SocketChannel)} repeatedly
+ * until it finally returns a {@link ByteBuffer} that can be used for getting data.
+ */
+ INITIAL,
+
+ /**
+ * Indicates that the {@link IBuffer} can provide a {@link ByteBuffer} that can be used for putting data.
+ * <p>
+ * A transition to {@link #WRITING} can be triggered by calling {@link IBuffer#write(SocketChannel)}.
+ * <p>
+ * A transition to {@link #GETTING} can be triggered by calling {@link IBuffer#flip()}.
+ * <p>
+ * A transition to {@link #INITIAL} can be triggered by calling {@link IBuffer#clear()}.
+ */
+ PUTTING,
+
+ /**
+ * Indicates that the {@link IBuffer} is currently writing its data to a {@link SocketChannel}.
+ * <p>
+ * Self transitions to {@link #WRITING} can be triggered by repeatedly calling {@link IBuffer#write(SocketChannel)}
+ * until it returns <code>true</code>.
+ * <p>
+ * A transition to {@link #INITIAL} can be triggered by calling {@link IBuffer#clear()}.
+ */
+ WRITING,
+
+ /**
+ * Indicates that the {@link IBuffer} is currently reading its header from a {@link SocketChannel}.
+ * <p>
+ * Transitions to {@link #READING_HEADER}, {@link #READING_BODY} or {@link #GETTING} can be triggered by repeatedly
+ * calling {@link IBuffer#startGetting(SocketChannel)} until it returns a {@link ByteBuffer} that can be used for
+ * getting data.
+ * <p>
+ * A transition to {@link #INITIAL} can be triggered by calling {@link IBuffer#clear()}.
+ */
+ READING_HEADER,
+
+ /**
+ * Indicates that the {@link IBuffer} is currently reading its body from a {@link SocketChannel}.
+ * <p>
+ * Transitions to {@link #READING_BODY} or {@link #GETTING} can be triggered by repeatedly calling
+ * {@link IBuffer#startGetting(SocketChannel)} until it returns a {@link ByteBuffer} that can be used for getting
+ * data.
+ * <p>
+ * A transition to {@link #INITIAL} can be triggered by calling {@link IBuffer#clear()}.
+ */
+ READING_BODY,
+
+ /**
+ * Indicates that the {@link IBuffer} can provide a {@link ByteBuffer} that can be used for getting data.
+ * <p>
+ * A transition to {@link #INITIAL} can be triggered by calling {@link IBuffer#clear()}.
+ */
+ GETTING,
+
+ /**
+ * Indicates that the {@link IBuffer} is owned by its {@link IBufferProvider}.
+ *
+ * @since 3.0
+ */
+ RELEASED,
+
+ /**
+ * Indicates that the {@link IBuffer} can not be used anymore.
+ *
+ * @since 3.0
+ */
+ DISPOSED
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/buffer/IBuffer.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/buffer/IBuffer.java
index 3907368e37..5814f3ba54 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/buffer/IBuffer.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/buffer/IBuffer.java
@@ -1,286 +1,286 @@
-/*
- * 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.buffer;
-
-import org.eclipse.net4j.channel.IChannel;
-import org.eclipse.net4j.util.IErrorHandler;
-
-import java.io.IOException;
-import java.nio.ByteBuffer;
-import java.nio.channels.SocketChannel;
-
-/**
- * Basic <b>unit of transport</b> in Net4j.
- * <p>
- * A buffer is well prepared for the usage with asynchronous {@link IChannel}s but can also be used with pure
- * {@link SocketChannel}s. All methods of <code>IBuffer</code> are non-blocking.
- * <p>
- * Usually buffers are obtained from a {@link IBufferProvider}. Buffers can be accessed, passed around and finally
- * {@link #release() released} to their original provider. The capacity of a buffer is determined by its provider.
- * <p>
- * In addition to its payload data each buffer contains an internal header of four bytes, two of them representing a
- * channel identifier the other two of them denoting the length of the payload data. The payload data may be accessed
- * through a {@link #getByteBuffer() ByteBuffer}.
- * <p>
- * This interface is <b>not</b> intended to be implemented by clients.
- * <p>
- * <dt><b>Class Diagram:</b></dt>
- * <dd><img src="doc-files/IBuffer-1.gif" title="Diagram Buffers" border="0" usemap="#IBuffer-1.gif"/></dd>
- * <p>
- * <MAP NAME="IBuffer-1.gif"> <AREA SHAPE="RECT" COORDS="303,12,403,72" HREF="IBufferHandler.html"> <AREA SHAPE="RECT"
- * COORDS="533,199,619,249" HREF="http://java.sun.com/j2se/1.5.0/docs/api/java/nio/ByteBuffer.html"> <AREA SHAPE="RECT"
- * COORDS="283,126,422,322" HREF="IBuffer.html"> <AREA SHAPE="RECT" COORDS="9,180,155,268" HREF="IBufferProvider.html">
- * <AREA SHAPE="RECT" COORDS="33,321,132,399" HREF="IBufferPool.html"></MAP>
- * <p>
- * <dt><b>State Machine Diagram:</b></dt>
- * <dd><img src="doc-files/BufferState-1.gif" title="Diagram Buffer States" border="0" usemap="#BufferState-1.gif"/></dd>
- * <p>
- * <MAP NAME="BufferState-1.gif"> <AREA SHAPE="RECT" COORDS="300,8,449,34" HREF="BufferState.html#INITIAL"> <AREA
- * SHAPE="RECT" COORDS="46,115,195,139" HREF="BufferState.html#PUTTING"> <AREA SHAPE="RECT" COORDS="48,271,195,295"
- * HREF="BufferState.html#WRITING"> <AREA SHAPE="RECT" COORDS="533,112,681,140" HREF="BufferState.html#READING_HEADER">
- * <AREA SHAPE="RECT" COORDS="533,271,680,295" HREF="BufferState.html#READING_BODY"> <AREA SHAPE="RECT"
- * COORDS="532,428,682,451" HREF="BufferState.html#GETTING"> </MAP>
- * <p>
- * An example for <b>putting</b> values into a buffer and writing it to a {@link SocketChannel}:
- * <p>
- *
- * <pre style="background-color:#ffffc8; border-width:1px; border-style:solid; padding:.5em;">
- * // Obtain a fresh buffer
- * Buffer buffer = bufferProvider.getBuffer(); // Start filling the buffer for channelID 4711 ByteBuffer byteBuffer =
- * buffer.startPutting(4711); byteBuffer.putDouble(15.47); // Write the contents of the Buffer to a // SocketChannel
- * without blocking while (!buffer.write(socketChannel)) { // Do something else }
- * </pre>
- *
- * An example for reading a buffer from a {@link SocketChannel} and <b>getting</b> values from it:
- * <p>
- *
- * <pre style="background-color:#ffffc8; border-width:1px; border-style:solid; padding:.5em;">
- * // Obtain a fresh buffer
- * Buffer buffer = bufferProvider.getBuffer();
- *
- * // Read the contents of the Buffer from a SocketChannel without blocking
- * ByteBuffer byteBuffer;
- * while ((byteBuffer = buffer.startGetting(socketChannel)) == null)
- * {
- * // Do something else
- * }
- *
- * // Access the contents of the buffer and release it to its provider
- * double value = byteBuffer.getDouble();
- * buffer.release();
- * </pre>
- *
- * @see IBufferProvider
- * @see IChannel#sendBuffer(IBuffer)
- * @see IChannel#setReceiveHandler(IBufferHandler)
- * @see IBufferHandler#handleBuffer(IBuffer)
- * @author Eike Stepper
- * @noextend This interface is not intended to be extended by clients.
- * @noimplement This interface is not intended to be implemented by clients.
- */
-public interface IBuffer
-{
- /**
- * Possible argument value of {@link #startPutting(short)} and possible return value of {@link #getChannelID()} that
- * indicates that this buffer is not intended to be passed to a {@link SocketChannel}.
- */
- public static final short NO_CHANNEL = Short.MIN_VALUE;
-
- /**
- * @since 2.0
- */
- public static final short MIN_CHANNEL = 1;
-
- /**
- * @since 2.0
- */
- public static final short MAX_CHANNEL = Short.MAX_VALUE;
-
- public static final short HEADER_SIZE = 4;
-
- /**
- * Returns the {@link IBufferProvider} that has provided this buffer and that this buffer will be returned to when its
- * {@link #release()} method is called.
- */
- public IBufferProvider getBufferProvider();
-
- /**
- * Returns the channel index value stored in the header of this buffer.
- *
- * @since 2.0
- */
- public short getChannelID();
-
- /**
- * Returns the capacity of this buffer.
- * <p>
- * The capacity of this buffer is equal to the {@link IBufferProvider#getBufferCapacity() capacity} of the
- * {@link IBufferProvider} that has provided this buffer.
- */
- public short getCapacity();
-
- /**
- * Returns the internal state of this buffer.
- */
- public BufferState getState();
-
- /**
- * Tries to read a {@link ByteBuffer} from a {@link SocketChannel} that can be used for getting data.
- * <p>
- * This method is non-blocking and it can be necessary to repeatedly call it. If it was not possible to read a
- * complete header from the <code>SocketChannel</code> <code>null</code> is returned and the state of this buffer is
- * {@link BufferState#READING_HEADER READING_HEADER}. If it was not possible to read a complete body from the
- * <code>SocketChannel</code> <code>null</code> is returned and the state of this buffer is
- * {@link BufferState#READING_BODY READING_BODY}.
- * <p>
- * If a <code>ByteBuffer</code> is returned it <b>may only</b> be used for getting data. It is left to the
- * responsibility of the caller that only the following methods of that <code>ByteBuffer</code> are used:
- * <ul>
- * <li> {@link ByteBuffer#get()}
- * <li> {@link ByteBuffer#get(byte[])}
- * <li> {@link ByteBuffer#get(int)}
- * <li> {@link ByteBuffer#get(byte[], int, int)}
- * <li> {@link ByteBuffer#getChar()}
- * <li> {@link ByteBuffer#getChar(int)}
- * <li> {@link ByteBuffer#getDouble()}
- * <li> {@link ByteBuffer#getDouble(int)}
- * <li> {@link ByteBuffer#getFloat()}
- * <li> {@link ByteBuffer#getFloat(int)}
- * <li> {@link ByteBuffer#getInt()}
- * <li> {@link ByteBuffer#getInt(int)}
- * <li> {@link ByteBuffer#getLong()}
- * <li> {@link ByteBuffer#getLong(int)}
- * <li> {@link ByteBuffer#getShort()}
- * <li> {@link ByteBuffer#getShort(int)}
- * <li>all other methods that do not influence {@link ByteBuffer#position()}, {@link ByteBuffer#limit()} and
- * {@link ByteBuffer#capacity()}
- * </ul>
- *
- * @param socketChannel
- * The <code>socketChannel</code> to read the {@link ByteBuffer} from.
- * @return A {@link ByteBuffer} that can be used for getting data if it was possible to completely read the data from
- * the given <code>SocketChannel</code>, <code>null</code> otherwise.
- * @throws IllegalStateException
- * If the state of this buffer is not {@link BufferState#INITIAL INITIAL},
- * {@link BufferState#READING_HEADER READING_HEADER} or {@link BufferState#READING_BODY READING_BODY}.
- * @throws IOException
- * If the <code>SocketChannel</code> has been closed or discovers other I/O problems.
- */
- public ByteBuffer startGetting(SocketChannel socketChannel) throws IllegalStateException, IOException;
-
- /**
- * Returns a {@link ByteBuffer} that can be used for putting data.
- * <p>
- * Turns the {@link #getState() state} of this buffer into {@link BufferState#PUTTING PUTTING}.
- * <p>
- * The returned <code>ByteBuffer</code> <b>may only</b> be used for putting data. It is left to the responsibility of
- * the caller that only the following methods of that <code>ByteBuffer</code> are used:
- * <ul>
- * <li> {@link ByteBuffer#put(byte)}
- * <li> {@link ByteBuffer#put(byte[])}
- * <li> {@link ByteBuffer#put(ByteBuffer)}
- * <li> {@link ByteBuffer#put(int, byte)}
- * <li> {@link ByteBuffer#put(byte[], int, int)}
- * <li> {@link ByteBuffer#putChar(char)}
- * <li> {@link ByteBuffer#putChar(int, char)}
- * <li> {@link ByteBuffer#putDouble(double)}
- * <li> {@link ByteBuffer#putDouble(int, double)}
- * <li> {@link ByteBuffer#putFloat(float)}
- * <li> {@link ByteBuffer#putFloat(int, float)}
- * <li> {@link ByteBuffer#putInt(int)}
- * <li> {@link ByteBuffer#putInt(int, int)}
- * <li> {@link ByteBuffer#putLong(long)}
- * <li> {@link ByteBuffer#putLong(int, long)}
- * <li> {@link ByteBuffer#putShort(short)}
- * <li> {@link ByteBuffer#putShort(int, short)}
- * <li>all other methods that do not influence {@link ByteBuffer#position()}, {@link ByteBuffer#limit()} and
- * {@link ByteBuffer#capacity()}
- * </ul>
- *
- * @param channelID
- * The index of an {@link IChannel} that this buffer is intended to be passed to later or {@link #NO_CHANNEL}
- * .
- * @return A {@link ByteBuffer} that can be used for putting data.
- * @throws IllegalStateException
- * If the state of this buffer is not {@link BufferState#INITIAL INITIAL} ({@link BufferState#PUTTING
- * PUTTING} is allowed but meaningless if and only if the given <code>channelID</code> is equal to the
- * existing <code>channelID</code> of this buffer).
- */
- public ByteBuffer startPutting(short channelID) throws IllegalStateException;
-
- /**
- * Tries to write the data of this buffer to a {@link SocketChannel}.
- * <p>
- * This method is non-blocking and it can be necessary to repeatedly call it. If it was not possible to completely
- * write the data to the <code>SocketChannel</code> <code>false</code> is returned and the state of this buffer
- * remains {@link BufferState#WRITING WRITING}.
- *
- * @param socketChannel
- * The <code>socketChannel</code> to write the data to.
- * @return <code>true</code> if it was possible to completely write the data to the <code>SocketChannel</code>,
- * <code>false</code> otherwise.
- * @throws IllegalStateException
- * If the state of this buffer is not {@link BufferState#PUTTING PUTTING} or {@link BufferState#WRITING
- * WRITING}.
- * @throws IOException
- * If the <code>SocketChannel</code> has been closed or discovers other I/O problems.
- */
- public boolean write(SocketChannel socketChannel) throws IllegalStateException, IOException;
-
- /**
- * Turns the state of this buffer from {@link BufferState#PUTTING PUTTING} into {@link BufferState#GETTING GETTING}.
- *
- * @throws IllegalStateException
- * If the state of this buffer is not {@link BufferState#PUTTING PUTTING}.
- */
- public void flip() throws IllegalStateException;
-
- /**
- * Returns the <code>ByteBuffer</code> that can be used for putting or getting data.
- *
- * @throws IllegalStateException
- * If the state of this buffer is not {@link BufferState#PUTTING PUTTING} or {@link BufferState#GETTING
- * GETTING}.
- */
- public ByteBuffer getByteBuffer() throws IllegalStateException;
-
- /**
- * Returns the <em>End Of Stream</em> flag to indicate whether this buffer is the last buffer in a stream of buffers.
- */
- public boolean isEOS();
-
- /**
- * Sets the <em>End Of Stream</em> flag to indicate whether this buffer is the last buffer in a stream of buffers.
- */
- public void setEOS(boolean eos);
-
- /**
- * Releases this buffer to its original {@link IBufferProvider}.
- */
- public void release();
-
- /**
- * Turns the state of this buffer from any state into {@link BufferState#INITIAL INITIAL}.
- */
- public void clear();
-
- public String formatContent(boolean showHeader);
-
- /**
- * @since 2.0
- */
- public IErrorHandler getErrorHandler();
-
- /**
- * @since 2.0
- */
- public void setErrorHandler(IErrorHandler errorHandler);
-}
+/*
+ * 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.buffer;
+
+import org.eclipse.net4j.channel.IChannel;
+import org.eclipse.net4j.util.IErrorHandler;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.channels.SocketChannel;
+
+/**
+ * Basic <b>unit of transport</b> in Net4j.
+ * <p>
+ * A buffer is well prepared for the usage with asynchronous {@link IChannel}s but can also be used with pure
+ * {@link SocketChannel}s. All methods of <code>IBuffer</code> are non-blocking.
+ * <p>
+ * Usually buffers are obtained from a {@link IBufferProvider}. Buffers can be accessed, passed around and finally
+ * {@link #release() released} to their original provider. The capacity of a buffer is determined by its provider.
+ * <p>
+ * In addition to its payload data each buffer contains an internal header of four bytes, two of them representing a
+ * channel identifier the other two of them denoting the length of the payload data. The payload data may be accessed
+ * through a {@link #getByteBuffer() ByteBuffer}.
+ * <p>
+ * This interface is <b>not</b> intended to be implemented by clients.
+ * <p>
+ * <dt><b>Class Diagram:</b></dt>
+ * <dd><img src="doc-files/IBuffer-1.gif" title="Diagram Buffers" border="0" usemap="#IBuffer-1.gif"/></dd>
+ * <p>
+ * <MAP NAME="IBuffer-1.gif"> <AREA SHAPE="RECT" COORDS="303,12,403,72" HREF="IBufferHandler.html"> <AREA SHAPE="RECT"
+ * COORDS="533,199,619,249" HREF="http://java.sun.com/j2se/1.5.0/docs/api/java/nio/ByteBuffer.html"> <AREA SHAPE="RECT"
+ * COORDS="283,126,422,322" HREF="IBuffer.html"> <AREA SHAPE="RECT" COORDS="9,180,155,268" HREF="IBufferProvider.html">
+ * <AREA SHAPE="RECT" COORDS="33,321,132,399" HREF="IBufferPool.html"></MAP>
+ * <p>
+ * <dt><b>State Machine Diagram:</b></dt>
+ * <dd><img src="doc-files/BufferState-1.gif" title="Diagram Buffer States" border="0" usemap="#BufferState-1.gif"/></dd>
+ * <p>
+ * <MAP NAME="BufferState-1.gif"> <AREA SHAPE="RECT" COORDS="300,8,449,34" HREF="BufferState.html#INITIAL"> <AREA
+ * SHAPE="RECT" COORDS="46,115,195,139" HREF="BufferState.html#PUTTING"> <AREA SHAPE="RECT" COORDS="48,271,195,295"
+ * HREF="BufferState.html#WRITING"> <AREA SHAPE="RECT" COORDS="533,112,681,140" HREF="BufferState.html#READING_HEADER">
+ * <AREA SHAPE="RECT" COORDS="533,271,680,295" HREF="BufferState.html#READING_BODY"> <AREA SHAPE="RECT"
+ * COORDS="532,428,682,451" HREF="BufferState.html#GETTING"> </MAP>
+ * <p>
+ * An example for <b>putting</b> values into a buffer and writing it to a {@link SocketChannel}:
+ * <p>
+ *
+ * <pre style="background-color:#ffffc8; border-width:1px; border-style:solid; padding:.5em;">
+ * // Obtain a fresh buffer
+ * Buffer buffer = bufferProvider.getBuffer(); // Start filling the buffer for channelID 4711 ByteBuffer byteBuffer =
+ * buffer.startPutting(4711); byteBuffer.putDouble(15.47); // Write the contents of the Buffer to a // SocketChannel
+ * without blocking while (!buffer.write(socketChannel)) { // Do something else }
+ * </pre>
+ *
+ * An example for reading a buffer from a {@link SocketChannel} and <b>getting</b> values from it:
+ * <p>
+ *
+ * <pre style="background-color:#ffffc8; border-width:1px; border-style:solid; padding:.5em;">
+ * // Obtain a fresh buffer
+ * Buffer buffer = bufferProvider.getBuffer();
+ *
+ * // Read the contents of the Buffer from a SocketChannel without blocking
+ * ByteBuffer byteBuffer;
+ * while ((byteBuffer = buffer.startGetting(socketChannel)) == null)
+ * {
+ * // Do something else
+ * }
+ *
+ * // Access the contents of the buffer and release it to its provider
+ * double value = byteBuffer.getDouble();
+ * buffer.release();
+ * </pre>
+ *
+ * @see IBufferProvider
+ * @see IChannel#sendBuffer(IBuffer)
+ * @see IChannel#setReceiveHandler(IBufferHandler)
+ * @see IBufferHandler#handleBuffer(IBuffer)
+ * @author Eike Stepper
+ * @noextend This interface is not intended to be extended by clients.
+ * @noimplement This interface is not intended to be implemented by clients.
+ */
+public interface IBuffer
+{
+ /**
+ * Possible argument value of {@link #startPutting(short)} and possible return value of {@link #getChannelID()} that
+ * indicates that this buffer is not intended to be passed to a {@link SocketChannel}.
+ */
+ public static final short NO_CHANNEL = Short.MIN_VALUE;
+
+ /**
+ * @since 2.0
+ */
+ public static final short MIN_CHANNEL = 1;
+
+ /**
+ * @since 2.0
+ */
+ public static final short MAX_CHANNEL = Short.MAX_VALUE;
+
+ public static final short HEADER_SIZE = 4;
+
+ /**
+ * Returns the {@link IBufferProvider} that has provided this buffer and that this buffer will be returned to when its
+ * {@link #release()} method is called.
+ */
+ public IBufferProvider getBufferProvider();
+
+ /**
+ * Returns the channel index value stored in the header of this buffer.
+ *
+ * @since 2.0
+ */
+ public short getChannelID();
+
+ /**
+ * Returns the capacity of this buffer.
+ * <p>
+ * The capacity of this buffer is equal to the {@link IBufferProvider#getBufferCapacity() capacity} of the
+ * {@link IBufferProvider} that has provided this buffer.
+ */
+ public short getCapacity();
+
+ /**
+ * Returns the internal state of this buffer.
+ */
+ public BufferState getState();
+
+ /**
+ * Tries to read a {@link ByteBuffer} from a {@link SocketChannel} that can be used for getting data.
+ * <p>
+ * This method is non-blocking and it can be necessary to repeatedly call it. If it was not possible to read a
+ * complete header from the <code>SocketChannel</code> <code>null</code> is returned and the state of this buffer is
+ * {@link BufferState#READING_HEADER READING_HEADER}. If it was not possible to read a complete body from the
+ * <code>SocketChannel</code> <code>null</code> is returned and the state of this buffer is
+ * {@link BufferState#READING_BODY READING_BODY}.
+ * <p>
+ * If a <code>ByteBuffer</code> is returned it <b>may only</b> be used for getting data. It is left to the
+ * responsibility of the caller that only the following methods of that <code>ByteBuffer</code> are used:
+ * <ul>
+ * <li> {@link ByteBuffer#get()}
+ * <li> {@link ByteBuffer#get(byte[])}
+ * <li> {@link ByteBuffer#get(int)}
+ * <li> {@link ByteBuffer#get(byte[], int, int)}
+ * <li> {@link ByteBuffer#getChar()}
+ * <li> {@link ByteBuffer#getChar(int)}
+ * <li> {@link ByteBuffer#getDouble()}
+ * <li> {@link ByteBuffer#getDouble(int)}
+ * <li> {@link ByteBuffer#getFloat()}
+ * <li> {@link ByteBuffer#getFloat(int)}
+ * <li> {@link ByteBuffer#getInt()}
+ * <li> {@link ByteBuffer#getInt(int)}
+ * <li> {@link ByteBuffer#getLong()}
+ * <li> {@link ByteBuffer#getLong(int)}
+ * <li> {@link ByteBuffer#getShort()}
+ * <li> {@link ByteBuffer#getShort(int)}
+ * <li>all other methods that do not influence {@link ByteBuffer#position()}, {@link ByteBuffer#limit()} and
+ * {@link ByteBuffer#capacity()}
+ * </ul>
+ *
+ * @param socketChannel
+ * The <code>socketChannel</code> to read the {@link ByteBuffer} from.
+ * @return A {@link ByteBuffer} that can be used for getting data if it was possible to completely read the data from
+ * the given <code>SocketChannel</code>, <code>null</code> otherwise.
+ * @throws IllegalStateException
+ * If the state of this buffer is not {@link BufferState#INITIAL INITIAL},
+ * {@link BufferState#READING_HEADER READING_HEADER} or {@link BufferState#READING_BODY READING_BODY}.
+ * @throws IOException
+ * If the <code>SocketChannel</code> has been closed or discovers other I/O problems.
+ */
+ public ByteBuffer startGetting(SocketChannel socketChannel) throws IllegalStateException, IOException;
+
+ /**
+ * Returns a {@link ByteBuffer} that can be used for putting data.
+ * <p>
+ * Turns the {@link #getState() state} of this buffer into {@link BufferState#PUTTING PUTTING}.
+ * <p>
+ * The returned <code>ByteBuffer</code> <b>may only</b> be used for putting data. It is left to the responsibility of
+ * the caller that only the following methods of that <code>ByteBuffer</code> are used:
+ * <ul>
+ * <li> {@link ByteBuffer#put(byte)}
+ * <li> {@link ByteBuffer#put(byte[])}
+ * <li> {@link ByteBuffer#put(ByteBuffer)}
+ * <li> {@link ByteBuffer#put(int, byte)}
+ * <li> {@link ByteBuffer#put(byte[], int, int)}
+ * <li> {@link ByteBuffer#putChar(char)}
+ * <li> {@link ByteBuffer#putChar(int, char)}
+ * <li> {@link ByteBuffer#putDouble(double)}
+ * <li> {@link ByteBuffer#putDouble(int, double)}
+ * <li> {@link ByteBuffer#putFloat(float)}
+ * <li> {@link ByteBuffer#putFloat(int, float)}
+ * <li> {@link ByteBuffer#putInt(int)}
+ * <li> {@link ByteBuffer#putInt(int, int)}
+ * <li> {@link ByteBuffer#putLong(long)}
+ * <li> {@link ByteBuffer#putLong(int, long)}
+ * <li> {@link ByteBuffer#putShort(short)}
+ * <li> {@link ByteBuffer#putShort(int, short)}
+ * <li>all other methods that do not influence {@link ByteBuffer#position()}, {@link ByteBuffer#limit()} and
+ * {@link ByteBuffer#capacity()}
+ * </ul>
+ *
+ * @param channelID
+ * The index of an {@link IChannel} that this buffer is intended to be passed to later or {@link #NO_CHANNEL}
+ * .
+ * @return A {@link ByteBuffer} that can be used for putting data.
+ * @throws IllegalStateException
+ * If the state of this buffer is not {@link BufferState#INITIAL INITIAL} ({@link BufferState#PUTTING
+ * PUTTING} is allowed but meaningless if and only if the given <code>channelID</code> is equal to the
+ * existing <code>channelID</code> of this buffer).
+ */
+ public ByteBuffer startPutting(short channelID) throws IllegalStateException;
+
+ /**
+ * Tries to write the data of this buffer to a {@link SocketChannel}.
+ * <p>
+ * This method is non-blocking and it can be necessary to repeatedly call it. If it was not possible to completely
+ * write the data to the <code>SocketChannel</code> <code>false</code> is returned and the state of this buffer
+ * remains {@link BufferState#WRITING WRITING}.
+ *
+ * @param socketChannel
+ * The <code>socketChannel</code> to write the data to.
+ * @return <code>true</code> if it was possible to completely write the data to the <code>SocketChannel</code>,
+ * <code>false</code> otherwise.
+ * @throws IllegalStateException
+ * If the state of this buffer is not {@link BufferState#PUTTING PUTTING} or {@link BufferState#WRITING
+ * WRITING}.
+ * @throws IOException
+ * If the <code>SocketChannel</code> has been closed or discovers other I/O problems.
+ */
+ public boolean write(SocketChannel socketChannel) throws IllegalStateException, IOException;
+
+ /**
+ * Turns the state of this buffer from {@link BufferState#PUTTING PUTTING} into {@link BufferState#GETTING GETTING}.
+ *
+ * @throws IllegalStateException
+ * If the state of this buffer is not {@link BufferState#PUTTING PUTTING}.
+ */
+ public void flip() throws IllegalStateException;
+
+ /**
+ * Returns the <code>ByteBuffer</code> that can be used for putting or getting data.
+ *
+ * @throws IllegalStateException
+ * If the state of this buffer is not {@link BufferState#PUTTING PUTTING} or {@link BufferState#GETTING
+ * GETTING}.
+ */
+ public ByteBuffer getByteBuffer() throws IllegalStateException;
+
+ /**
+ * Returns the <em>End Of Stream</em> flag to indicate whether this buffer is the last buffer in a stream of buffers.
+ */
+ public boolean isEOS();
+
+ /**
+ * Sets the <em>End Of Stream</em> flag to indicate whether this buffer is the last buffer in a stream of buffers.
+ */
+ public void setEOS(boolean eos);
+
+ /**
+ * Releases this buffer to its original {@link IBufferProvider}.
+ */
+ public void release();
+
+ /**
+ * Turns the state of this buffer from any state into {@link BufferState#INITIAL INITIAL}.
+ */
+ public void clear();
+
+ public String formatContent(boolean showHeader);
+
+ /**
+ * @since 2.0
+ */
+ public IErrorHandler getErrorHandler();
+
+ /**
+ * @since 2.0
+ */
+ public void setErrorHandler(IErrorHandler errorHandler);
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/buffer/IBufferHandler.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/buffer/IBufferHandler.java
index 6b079c6413..500d24ae70 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/buffer/IBufferHandler.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/buffer/IBufferHandler.java
@@ -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
- */
-package org.eclipse.net4j.buffer;
-
-/**
- * Provides clients with the ability to pass {@link IBuffer}s in for further buffer handling.
- *
- * @author Eike Stepper
- */
-public interface IBufferHandler
-{
- /**
- * Handles an {@link IBuffer} and optionally releases it. The implementor of this method takes over the ownership of
- * the buffer. Care must be taken to properly {@link IBuffer#release() release} the buffer if the ownership is not
- * explicitely passed to some further party.
- *
- * @param buffer
- * The buffer to be handled and otionally released.
- */
- public void handleBuffer(IBuffer 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.buffer;
+
+/**
+ * Provides clients with the ability to pass {@link IBuffer}s in for further buffer handling.
+ *
+ * @author Eike Stepper
+ */
+public interface IBufferHandler
+{
+ /**
+ * Handles an {@link IBuffer} and optionally releases it. The implementor of this method takes over the ownership of
+ * the buffer. Care must be taken to properly {@link IBuffer#release() release} the buffer if the ownership is not
+ * explicitely passed to some further party.
+ *
+ * @param buffer
+ * The buffer to be handled and otionally released.
+ */
+ public void handleBuffer(IBuffer buffer);
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/buffer/IBufferPool.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/buffer/IBufferPool.java
index f48bf9cc26..beaca3144b 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/buffer/IBufferPool.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/buffer/IBufferPool.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.buffer;
-
-/**
- * Provides clients with the ability to obtain and retain pooled {@link IBuffer}s.
- *
- * @author Eike Stepper
- */
-public interface IBufferPool extends IBufferProvider
-{
- /**
- * Tries to remove a single buffer from this <code>BufferPool</code> and {@link IBuffer#release() release} it.
- *
- * @return <code>true</code> if a buffer could be evicted, <code>false</code> otherwise.
- */
- public boolean evictOne();
-
- /**
- * Tries to remove as many buffers from this <code>BufferPool</code> and {@link IBuffer#release() release} them as are
- * needed to let a given maximum number of buffers survive in the pool.
- *
- * @return The number of buffers that could be evicted.
- */
- public int evict(int survivors);
-
- /**
- * Offers additional introspection features for {@link IBufferPool}s.
- *
- * @author Eike Stepper
- */
- public interface Introspection extends IBufferPool, IBufferProvider.Introspection
- {
- /**
- * Returns the number of buffers that are currently pooled in this <code>BufferPool</code>.
- */
- public int getPooledBuffers();
- }
-}
+/*
+ * 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.buffer;
+
+/**
+ * Provides clients with the ability to obtain and retain pooled {@link IBuffer}s.
+ *
+ * @author Eike Stepper
+ */
+public interface IBufferPool extends IBufferProvider
+{
+ /**
+ * Tries to remove a single buffer from this <code>BufferPool</code> and {@link IBuffer#release() release} it.
+ *
+ * @return <code>true</code> if a buffer could be evicted, <code>false</code> otherwise.
+ */
+ public boolean evictOne();
+
+ /**
+ * Tries to remove as many buffers from this <code>BufferPool</code> and {@link IBuffer#release() release} them as are
+ * needed to let a given maximum number of buffers survive in the pool.
+ *
+ * @return The number of buffers that could be evicted.
+ */
+ public int evict(int survivors);
+
+ /**
+ * Offers additional introspection features for {@link IBufferPool}s.
+ *
+ * @author Eike Stepper
+ */
+ public interface Introspection extends IBufferPool, IBufferProvider.Introspection
+ {
+ /**
+ * Returns the number of buffers that are currently pooled in this <code>BufferPool</code>.
+ */
+ public int getPooledBuffers();
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/buffer/IBufferProvider.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/buffer/IBufferProvider.java
index 13f554e748..3f3eed8bdb 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/buffer/IBufferProvider.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/buffer/IBufferProvider.java
@@ -1,52 +1,52 @@
-/*
- * 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.buffer;
-
-/**
- * Provides clients with the ability to obtain and retain {@link IBuffer}s.
- *
- * @author Eike Stepper
- */
-public interface IBufferProvider
-{
- /**
- * Returns the capacity of the buffers provided by {@link #provideBuffer()} .
- */
- public short getBufferCapacity();
-
- /**
- * Provides a buffer from this <code>BufferProvider</code>.
- */
- public IBuffer provideBuffer();
-
- /**
- * Retains a buffer to this <code>BufferProvider</code>.
- */
- public void retainBuffer(IBuffer buffer);
-
- /**
- * Offers additional introspection features for {@link IBufferProvider}s.
- *
- * @author Eike Stepper
- */
- public interface Introspection extends IBufferProvider
- {
- /**
- * Returns the number of buffers that have already been provided by this <code>BufferProvider</code>.
- */
- public long getProvidedBuffers();
-
- /**
- * Returns the number of buffers that have already been retained to this <code>BufferProvider</code>.
- */
- public long getRetainedBuffers();
- }
-}
+/*
+ * 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.buffer;
+
+/**
+ * Provides clients with the ability to obtain and retain {@link IBuffer}s.
+ *
+ * @author Eike Stepper
+ */
+public interface IBufferProvider
+{
+ /**
+ * Returns the capacity of the buffers provided by {@link #provideBuffer()} .
+ */
+ public short getBufferCapacity();
+
+ /**
+ * Provides a buffer from this <code>BufferProvider</code>.
+ */
+ public IBuffer provideBuffer();
+
+ /**
+ * Retains a buffer to this <code>BufferProvider</code>.
+ */
+ public void retainBuffer(IBuffer buffer);
+
+ /**
+ * Offers additional introspection features for {@link IBufferProvider}s.
+ *
+ * @author Eike Stepper
+ */
+ public interface Introspection extends IBufferProvider
+ {
+ /**
+ * Returns the number of buffers that have already been provided by this <code>BufferProvider</code>.
+ */
+ public long getProvidedBuffers();
+
+ /**
+ * Returns the number of buffers that have already been retained to this <code>BufferProvider</code>.
+ */
+ public long getRetainedBuffers();
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/buffer/package-info.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/buffer/package-info.java
index c17b672592..b3f9f777b4 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/buffer/package-info.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/buffer/package-info.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
+ * 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
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/channel/ChannelException.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/channel/ChannelException.java
index 2bf49526dc..df43fed9e8 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/channel/ChannelException.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/channel/ChannelException.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.channel;
-
-/**
- * Thrown by an {@link IChannel} to indicate channel management problems.
- *
- * @see IChannelMultiplexer
- * @author Eike Stepper
- * @since 2.0
- * @noextend This interface is not intended to be extended by clients.
- */
-public class ChannelException extends RuntimeException
-{
- private static final long serialVersionUID = 1L;
-
- public ChannelException()
- {
- }
-
- public ChannelException(String message)
- {
- super(message);
- }
-
- public ChannelException(Throwable cause)
- {
- super(cause);
- }
-
- public ChannelException(String message, Throwable cause)
- {
- super(message, cause);
- }
-}
+/*
+ * 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.channel;
+
+/**
+ * Thrown by an {@link IChannel} to indicate channel management problems.
+ *
+ * @see IChannelMultiplexer
+ * @author Eike Stepper
+ * @since 2.0
+ * @noextend This interface is not intended to be extended by clients.
+ */
+public class ChannelException extends RuntimeException
+{
+ private static final long serialVersionUID = 1L;
+
+ public ChannelException()
+ {
+ }
+
+ public ChannelException(String message)
+ {
+ super(message);
+ }
+
+ public ChannelException(Throwable cause)
+ {
+ super(cause);
+ }
+
+ public ChannelException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/channel/ChannelInputStream.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/channel/ChannelInputStream.java
index e9750272de..6fff240199 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/channel/ChannelInputStream.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/channel/ChannelInputStream.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.channel;
-
-import org.eclipse.net4j.buffer.BufferInputStream;
-import org.eclipse.net4j.buffer.IBuffer;
-
-import java.io.InputStream;
-
-/**
- * An {@link InputStream input stream} that provides the {@link IBuffer buffers} which arrive at a {@link IChannel
- * channel} as a continuous byte sequence.
- *
- * @author Eike Stepper
- */
-public class ChannelInputStream extends BufferInputStream
-{
- private IChannel channel;
-
- private long millisBeforeTimeout = DEFAULT_MILLIS_BEFORE_TIMEOUT;
-
- private long millisInterruptCheck = DEFAULT_MILLIS_INTERRUPT_CHECK;
-
- public ChannelInputStream(IChannel channel)
- {
- this(channel, DEFAULT_MILLIS_BEFORE_TIMEOUT);
- }
-
- public ChannelInputStream(IChannel channel, long millisBeforeTimeout)
- {
- this.channel = channel;
- this.millisBeforeTimeout = millisBeforeTimeout;
-
- channel.setReceiveHandler(this);
- }
-
- public IChannel getChannel()
- {
- return channel;
- }
-
- @Override
- public long getMillisBeforeTimeout()
- {
- return millisBeforeTimeout;
- }
-
- public void setMillisBeforeTimeout(long millisBeforeTimeout)
- {
- this.millisBeforeTimeout = millisBeforeTimeout;
- }
-
- @Override
- public long getMillisInterruptCheck()
- {
- return millisInterruptCheck;
- }
-
- public void setMillisInterruptCheck(long millisInterruptCheck)
- {
- this.millisInterruptCheck = millisInterruptCheck;
- }
-
- @Override
- public String toString()
- {
- return "ChannelInputStream[" + channel + "]"; //$NON-NLS-1$ //$NON-NLS-2$
- }
-}
+/*
+ * 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.channel;
+
+import org.eclipse.net4j.buffer.BufferInputStream;
+import org.eclipse.net4j.buffer.IBuffer;
+
+import java.io.InputStream;
+
+/**
+ * An {@link InputStream input stream} that provides the {@link IBuffer buffers} which arrive at a {@link IChannel
+ * channel} as a continuous byte sequence.
+ *
+ * @author Eike Stepper
+ */
+public class ChannelInputStream extends BufferInputStream
+{
+ private IChannel channel;
+
+ private long millisBeforeTimeout = DEFAULT_MILLIS_BEFORE_TIMEOUT;
+
+ private long millisInterruptCheck = DEFAULT_MILLIS_INTERRUPT_CHECK;
+
+ public ChannelInputStream(IChannel channel)
+ {
+ this(channel, DEFAULT_MILLIS_BEFORE_TIMEOUT);
+ }
+
+ public ChannelInputStream(IChannel channel, long millisBeforeTimeout)
+ {
+ this.channel = channel;
+ this.millisBeforeTimeout = millisBeforeTimeout;
+
+ channel.setReceiveHandler(this);
+ }
+
+ public IChannel getChannel()
+ {
+ return channel;
+ }
+
+ @Override
+ public long getMillisBeforeTimeout()
+ {
+ return millisBeforeTimeout;
+ }
+
+ public void setMillisBeforeTimeout(long millisBeforeTimeout)
+ {
+ this.millisBeforeTimeout = millisBeforeTimeout;
+ }
+
+ @Override
+ public long getMillisInterruptCheck()
+ {
+ return millisInterruptCheck;
+ }
+
+ public void setMillisInterruptCheck(long millisInterruptCheck)
+ {
+ this.millisInterruptCheck = millisInterruptCheck;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "ChannelInputStream[" + channel + "]"; //$NON-NLS-1$ //$NON-NLS-2$
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/channel/ChannelOutputStream.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/channel/ChannelOutputStream.java
index 413374d154..0ca4b3dd4f 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/channel/ChannelOutputStream.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/channel/ChannelOutputStream.java
@@ -1,36 +1,36 @@
-/*
- * 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.channel;
-
-import org.eclipse.net4j.buffer.BufferOutputStream;
-import org.eclipse.net4j.buffer.IBuffer;
-import org.eclipse.net4j.buffer.IBufferProvider;
-
-import java.io.OutputStream;
-
-/**
- * An {@link OutputStream output stream} that fragments the written byte sequence into fixed-sized {@link IBuffer
- * buffers} and passes them to configured {@link IChannel channel}.
- *
- * @author Eike Stepper
- */
-public class ChannelOutputStream extends BufferOutputStream
-{
- public ChannelOutputStream(IChannel channel)
- {
- super(channel, channel.getID());
- }
-
- public ChannelOutputStream(IChannel channel, IBufferProvider bufferProvider)
- {
- super(channel, bufferProvider, channel == null ? IBuffer.NO_CHANNEL : channel.getID());
- }
-}
+/*
+ * 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.channel;
+
+import org.eclipse.net4j.buffer.BufferOutputStream;
+import org.eclipse.net4j.buffer.IBuffer;
+import org.eclipse.net4j.buffer.IBufferProvider;
+
+import java.io.OutputStream;
+
+/**
+ * An {@link OutputStream output stream} that fragments the written byte sequence into fixed-sized {@link IBuffer
+ * buffers} and passes them to configured {@link IChannel channel}.
+ *
+ * @author Eike Stepper
+ */
+public class ChannelOutputStream extends BufferOutputStream
+{
+ public ChannelOutputStream(IChannel channel)
+ {
+ super(channel, channel.getID());
+ }
+
+ public ChannelOutputStream(IChannel channel, IBufferProvider bufferProvider)
+ {
+ super(channel, bufferProvider, channel == null ? IBuffer.NO_CHANNEL : channel.getID());
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/channel/IChannel.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/channel/IChannel.java
index f851107ae2..cd34aee1d9 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/channel/IChannel.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/channel/IChannel.java
@@ -1,114 +1,114 @@
-/*
- * 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.channel;
-
-import org.eclipse.net4j.ILocationAware;
-import org.eclipse.net4j.buffer.IBuffer;
-import org.eclipse.net4j.buffer.IBufferHandler;
-import org.eclipse.net4j.connector.IConnector;
-import org.eclipse.net4j.util.collection.Closeable;
-import org.eclipse.net4j.util.event.INotifier;
-import org.eclipse.net4j.util.security.IUserAware;
-
-/**
- * A bidirectional communications channel for the asynchronous exchange of {@link IBuffer buffers}. A channel is
- * lightweight and virtual in the sense that it does not necessarily represent a single physical connection like a TCP
- * socket connection. The underlying physical connection is represented by a {@link IChannelMultiplexer channel
- * multiplexer}.
- * <p>
- * <dt><b>Class Diagram:</b></dt>
- * <dd><img src="doc-files/IChannel-1.gif" title="Diagram Buffers" border="0" usemap="#IChannel-1.gif"/></dd>
- * <p>
- * <MAP NAME="IChannel-1.gif"> <AREA SHAPE="RECT" COORDS="301,8,451,68" HREF="IChannelID.html"> <AREA SHAPE="RECT"
- * COORDS="301,141,451,211" HREF="IChannel.html"> <AREA SHAPE="RECT" COORDS="599,151,696,201"
- * HREF="../buffer/IBufferHandler.html"> <AREA SHAPE="RECT" COORDS="7,151,96,201" HREF="../connector/IConnector.html">
- * </MAP>
- * <p>
- * An example for opening a channel on an {@link IConnector} and sending an {@link IBuffer}:
- * <p>
- *
- * <pre style="background-color:#ffffc8; border-width:1px; border-style:solid; padding:.5em;">
- * // Open a channel
- * IChannel channel = connector.openChannel();
- * short channelID = channel.getIndex();
- *
- * // Fill a buffer
- * Buffer buffer = bufferProvider.getBuffer();
- * ByteBuffer byteBuffer = buffer.startPutting(channelID);
- * byteBuffer.putDouble(15.47);
- *
- * // Let the channel send the buffer without blocking
- * channel.sendBuffer(buffer);
- * </pre>
- * <p>
- * An example for receiving {@link IBuffer}s from channels on an {@link IConnector}:
- * <p>
- *
- * <pre style="background-color:#ffffc8; border-width:1px; border-style:solid; padding:.5em;">
- * // Create a receive handler
- * final IBufferHandler receiveHandler = new IBufferHandler()
- * {
- * public void handleBuffer(IBuffer buffer)
- * {
- * ByteBuffer byteBuffer = buffer.getByteBuffer();
- * IOUtil.OUT().println(&quot;Received &quot; + byteBuffer.getDouble());
- * buffer.release();
- * }
- * };
- *
- * // Set the receive handler to all new channels
- * connector.addListener(new ContainerEventAdapter()
- * {
- * protected void onAdded(IContainer container, Object element)
- * {
- * IChannel channel = (IChannel)element;
- * channel.setReceiveHandler(receiveHandler);
- * }
- * });
- * </pre>
- *
- * @author Eike Stepper
- * @noimplement This interface is not intended to be implemented by clients.
- * @noextend This interface is not intended to be extended by clients.
- */
-public interface IChannel extends ILocationAware, IUserAware, IBufferHandler, INotifier, Closeable
-{
- /**
- * Returns the ID of this channel. The ID is unique at any time among all channels of the associated
- * {@link IChannelMultiplexer multiplexer}.
- *
- * @since 2.0
- */
- public short getID();
-
- /**
- * Returns the multiplexer this channel is associated with. This channel multiplexer can be used, for example, to open
- * additional channels that will be multiplexed through the same transport medium.
- *
- * @since 2.0
- */
- public IChannelMultiplexer getMultiplexer();
-
- /**
- * Asynchronously sends the given buffer to the receive handler of the peer channel.
- */
- public void sendBuffer(IBuffer buffer);
-
- /**
- * Returns the <code>IBufferHandler</code> that handles buffers received from the peer channel.
- */
- public IBufferHandler getReceiveHandler();
-
- /**
- * Sets the <code>IBufferHandler</code> to handle buffers received from the peer channel.
- */
- public void setReceiveHandler(IBufferHandler receiveHandler);
-}
+/*
+ * 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.channel;
+
+import org.eclipse.net4j.ILocationAware;
+import org.eclipse.net4j.buffer.IBuffer;
+import org.eclipse.net4j.buffer.IBufferHandler;
+import org.eclipse.net4j.connector.IConnector;
+import org.eclipse.net4j.util.collection.Closeable;
+import org.eclipse.net4j.util.event.INotifier;
+import org.eclipse.net4j.util.security.IUserAware;
+
+/**
+ * A bidirectional communications channel for the asynchronous exchange of {@link IBuffer buffers}. A channel is
+ * lightweight and virtual in the sense that it does not necessarily represent a single physical connection like a TCP
+ * socket connection. The underlying physical connection is represented by a {@link IChannelMultiplexer channel
+ * multiplexer}.
+ * <p>
+ * <dt><b>Class Diagram:</b></dt>
+ * <dd><img src="doc-files/IChannel-1.gif" title="Diagram Buffers" border="0" usemap="#IChannel-1.gif"/></dd>
+ * <p>
+ * <MAP NAME="IChannel-1.gif"> <AREA SHAPE="RECT" COORDS="301,8,451,68" HREF="IChannelID.html"> <AREA SHAPE="RECT"
+ * COORDS="301,141,451,211" HREF="IChannel.html"> <AREA SHAPE="RECT" COORDS="599,151,696,201"
+ * HREF="../buffer/IBufferHandler.html"> <AREA SHAPE="RECT" COORDS="7,151,96,201" HREF="../connector/IConnector.html">
+ * </MAP>
+ * <p>
+ * An example for opening a channel on an {@link IConnector} and sending an {@link IBuffer}:
+ * <p>
+ *
+ * <pre style="background-color:#ffffc8; border-width:1px; border-style:solid; padding:.5em;">
+ * // Open a channel
+ * IChannel channel = connector.openChannel();
+ * short channelID = channel.getIndex();
+ *
+ * // Fill a buffer
+ * Buffer buffer = bufferProvider.getBuffer();
+ * ByteBuffer byteBuffer = buffer.startPutting(channelID);
+ * byteBuffer.putDouble(15.47);
+ *
+ * // Let the channel send the buffer without blocking
+ * channel.sendBuffer(buffer);
+ * </pre>
+ * <p>
+ * An example for receiving {@link IBuffer}s from channels on an {@link IConnector}:
+ * <p>
+ *
+ * <pre style="background-color:#ffffc8; border-width:1px; border-style:solid; padding:.5em;">
+ * // Create a receive handler
+ * final IBufferHandler receiveHandler = new IBufferHandler()
+ * {
+ * public void handleBuffer(IBuffer buffer)
+ * {
+ * ByteBuffer byteBuffer = buffer.getByteBuffer();
+ * IOUtil.OUT().println(&quot;Received &quot; + byteBuffer.getDouble());
+ * buffer.release();
+ * }
+ * };
+ *
+ * // Set the receive handler to all new channels
+ * connector.addListener(new ContainerEventAdapter()
+ * {
+ * protected void onAdded(IContainer container, Object element)
+ * {
+ * IChannel channel = (IChannel)element;
+ * channel.setReceiveHandler(receiveHandler);
+ * }
+ * });
+ * </pre>
+ *
+ * @author Eike Stepper
+ * @noimplement This interface is not intended to be implemented by clients.
+ * @noextend This interface is not intended to be extended by clients.
+ */
+public interface IChannel extends ILocationAware, IUserAware, IBufferHandler, INotifier, Closeable
+{
+ /**
+ * Returns the ID of this channel. The ID is unique at any time among all channels of the associated
+ * {@link IChannelMultiplexer multiplexer}.
+ *
+ * @since 2.0
+ */
+ public short getID();
+
+ /**
+ * Returns the multiplexer this channel is associated with. This channel multiplexer can be used, for example, to open
+ * additional channels that will be multiplexed through the same transport medium.
+ *
+ * @since 2.0
+ */
+ public IChannelMultiplexer getMultiplexer();
+
+ /**
+ * Asynchronously sends the given buffer to the receive handler of the peer channel.
+ */
+ public void sendBuffer(IBuffer buffer);
+
+ /**
+ * Returns the <code>IBufferHandler</code> that handles buffers received from the peer channel.
+ */
+ public IBufferHandler getReceiveHandler();
+
+ /**
+ * Sets the <code>IBufferHandler</code> to handle buffers received from the peer channel.
+ */
+ public void setReceiveHandler(IBufferHandler receiveHandler);
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/channel/IChannelMultiplexer.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/channel/IChannelMultiplexer.java
index b9e8b55257..e0414a2565 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/channel/IChannelMultiplexer.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/channel/IChannelMultiplexer.java
@@ -1,98 +1,98 @@
-/*
- * 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.channel;
-
-import org.eclipse.net4j.ILocationAware;
-import org.eclipse.net4j.buffer.IBufferHandler;
-import org.eclipse.net4j.protocol.IProtocol;
-import org.eclipse.net4j.util.container.IContainer;
-import org.eclipse.net4j.util.event.IListener;
-import org.eclipse.net4j.util.factory.IFactory;
-import org.eclipse.net4j.util.lifecycle.ILifecycle;
-
-import java.util.Collection;
-
-/**
- * Manages and multiplexes virtual data {@link IChannel channels} over a shared physical connection.
- *
- * @author Eike Stepper
- * @noimplement This interface is not intended to be implemented by clients.
- * @noextend This interface is not intended to be extended by clients.
- */
-public interface IChannelMultiplexer extends ILocationAware, IContainer<IChannel>
-{
- /**
- * @since 2.0
- */
- public static final long NO_CHANNEL_TIMEOUT = Long.MAX_VALUE;
-
- /**
- * Indicates to use the timeout that is configured via debug property <code>open.channel.timeout</code> (see .options
- * file) which has a default of 10 seconds.
- *
- * @since 2.0
- */
- public static final long DEFAULT_OPEN_CHANNEL_TIMEOUT = -1;
-
- /**
- * Synchronous request to open a new {@link IChannel} with an undefined channel protocol. Since the peer connector
- * can't lookup a protocol {@link IFactory factory} without a protocol identifier the {@link IBufferHandler} of the
- * peer {@link IChannel} can only be provided by externally provided channel {@link ILifecycle lifecycle}
- * {@link IListener listeners}.
- * <p>
- *
- * @see #openChannel(String, Object)
- * @see #openChannel(IProtocol)
- * @since 2.0
- */
- public IChannel openChannel() throws ChannelException;
-
- /**
- * Synchronous request to open a new {@link IChannel} with a channel protocol defined by a given protocol identifier.
- * The peer connector will lookup a protocol {@link IFactory factory} with the protocol identifier, create a
- * {@link IBufferHandler} and inject it into the peer {@link IChannel}.
- * <p>
- *
- * @see #openChannel()
- * @see #openChannel(IProtocol)
- * @since 2.0
- */
- public IChannel openChannel(String protocolID, Object infraStructure) throws ChannelException;
-
- /**
- * Synchronous request to open a new {@link IChannel} with the given channel protocol . The peer connector will lookup
- * a protocol {@link IFactory factory} with the protocol identifier, create a {@link IBufferHandler} and inject it
- * into the peer channel.
- * <p>
- *
- * @see #openChannel()
- * @see #openChannel(String, Object)
- * @since 2.0
- */
- public IChannel openChannel(IProtocol<?> protocol) throws ChannelException;
-
- /**
- * Returns a collection of currently open channels.
- *
- * @since 2.0
- */
- public Collection<IChannel> getChannels();
-
- /**
- * @since 2.0
- */
- public long getOpenChannelTimeout();
-
- /**
- * @since 2.0
- */
- public void setOpenChannelTimeout(long openChannelTimeout);
-}
+/*
+ * 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.channel;
+
+import org.eclipse.net4j.ILocationAware;
+import org.eclipse.net4j.buffer.IBufferHandler;
+import org.eclipse.net4j.protocol.IProtocol;
+import org.eclipse.net4j.util.container.IContainer;
+import org.eclipse.net4j.util.event.IListener;
+import org.eclipse.net4j.util.factory.IFactory;
+import org.eclipse.net4j.util.lifecycle.ILifecycle;
+
+import java.util.Collection;
+
+/**
+ * Manages and multiplexes virtual data {@link IChannel channels} over a shared physical connection.
+ *
+ * @author Eike Stepper
+ * @noimplement This interface is not intended to be implemented by clients.
+ * @noextend This interface is not intended to be extended by clients.
+ */
+public interface IChannelMultiplexer extends ILocationAware, IContainer<IChannel>
+{
+ /**
+ * @since 2.0
+ */
+ public static final long NO_CHANNEL_TIMEOUT = Long.MAX_VALUE;
+
+ /**
+ * Indicates to use the timeout that is configured via debug property <code>open.channel.timeout</code> (see .options
+ * file) which has a default of 10 seconds.
+ *
+ * @since 2.0
+ */
+ public static final long DEFAULT_OPEN_CHANNEL_TIMEOUT = -1;
+
+ /**
+ * Synchronous request to open a new {@link IChannel} with an undefined channel protocol. Since the peer connector
+ * can't lookup a protocol {@link IFactory factory} without a protocol identifier the {@link IBufferHandler} of the
+ * peer {@link IChannel} can only be provided by externally provided channel {@link ILifecycle lifecycle}
+ * {@link IListener listeners}.
+ * <p>
+ *
+ * @see #openChannel(String, Object)
+ * @see #openChannel(IProtocol)
+ * @since 2.0
+ */
+ public IChannel openChannel() throws ChannelException;
+
+ /**
+ * Synchronous request to open a new {@link IChannel} with a channel protocol defined by a given protocol identifier.
+ * The peer connector will lookup a protocol {@link IFactory factory} with the protocol identifier, create a
+ * {@link IBufferHandler} and inject it into the peer {@link IChannel}.
+ * <p>
+ *
+ * @see #openChannel()
+ * @see #openChannel(IProtocol)
+ * @since 2.0
+ */
+ public IChannel openChannel(String protocolID, Object infraStructure) throws ChannelException;
+
+ /**
+ * Synchronous request to open a new {@link IChannel} with the given channel protocol . The peer connector will lookup
+ * a protocol {@link IFactory factory} with the protocol identifier, create a {@link IBufferHandler} and inject it
+ * into the peer channel.
+ * <p>
+ *
+ * @see #openChannel()
+ * @see #openChannel(String, Object)
+ * @since 2.0
+ */
+ public IChannel openChannel(IProtocol<?> protocol) throws ChannelException;
+
+ /**
+ * Returns a collection of currently open channels.
+ *
+ * @since 2.0
+ */
+ public Collection<IChannel> getChannels();
+
+ /**
+ * @since 2.0
+ */
+ public long getOpenChannelTimeout();
+
+ /**
+ * @since 2.0
+ */
+ public void setOpenChannelTimeout(long openChannelTimeout);
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/channel/package-info.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/channel/package-info.java
index 184c158268..70c33b6374 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/channel/package-info.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/channel/package-info.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
+ * 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
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/connector/ConnectorCredentialsInjector.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/connector/ConnectorCredentialsInjector.java
index 39134b27ab..c12c78cee7 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/connector/ConnectorCredentialsInjector.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/connector/ConnectorCredentialsInjector.java
@@ -1,103 +1,103 @@
-/*
- * 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.connector;
-
-import org.eclipse.net4j.util.security.INegotiatorAware;
-import org.eclipse.net4j.util.security.IPasswordCredentialsProvider;
-import org.eclipse.net4j.util.security.ResponseNegotiator;
-import org.eclipse.net4j.util.security.ResponseNegotiatorInjector;
-import org.eclipse.net4j.util.security.SecurityUtil;
-
-/**
- * Injects a configurable response negotiator into selected client connectors.
- * <p>
- * An example:
- *
- * <pre>
- * IManagedContainer container = IPluginContainer.INSTANCE;
- *
- * String connectorDescription = &quot;localhost:2036&quot;;
- * String userID = &quot;name&quot;;
- * String password = &quot;secret&quot;;
- *
- * IPasswordCredentialsProvider credentialsProvider = new PasswordCredentialsProvider(userID, password);
- *
- * container.addPostProcessor(new ConnectorCredentialsInjector(connectorDescription, credentialsProvider));
- * IConnector connector = (IConnector)container.getElement(&quot;org.eclipse.net4j.connectors&quot;, &quot;tcp&quot;, connectorDescription);
- *
- * IChannel channel = connector.openChannel();
- * // ...
- * </pre>
- *
- * @author Eike Stepper
- * @since 2.0
- */
-public class ConnectorCredentialsInjector extends ResponseNegotiatorInjector
-{
- private String connectorDescription;
-
- /**
- * @param connectorDescription
- * The description of the IConnector that the negotiator shall be injected into, or <code>null</code> to
- * bypass the description check.
- */
- public ConnectorCredentialsInjector(String connectorDescription, IPasswordCredentialsProvider credentialsProvider,
- String algorithmName)
- {
- super(createNegotiator(credentialsProvider, algorithmName));
- this.connectorDescription = connectorDescription;
- }
-
- /**
- * @param connectorDescription
- * The description of the IConnector that the negotiator shall be injected into, or <code>null</code> to
- * bypass the description check.
- */
- public ConnectorCredentialsInjector(String connectorDescription, IPasswordCredentialsProvider credentialsProvider)
- {
- this(connectorDescription, credentialsProvider, SecurityUtil.PBE_WITH_MD5_AND_DES);
- }
-
- @Override
- protected boolean filterElement(String productGroup, String factoryType, String description,
- INegotiatorAware negotiatorAware)
- {
- if (negotiatorAware instanceof IConnector)
- {
- IConnector connector = (IConnector)negotiatorAware;
- if (connector.isClient())
- {
- return filterConnectorDescription(description);
- }
- }
-
- return false;
- }
-
- protected boolean filterConnectorDescription(String description)
- {
- if (connectorDescription == null)
- {
- return true;
- }
-
- return connectorDescription.equals(description);
- }
-
- private static ResponseNegotiator createNegotiator(IPasswordCredentialsProvider credentialsProvider,
- String algorithmName)
- {
- ResponseNegotiator negotiator = new ResponseNegotiator();
- negotiator.setCredentialsProvider(credentialsProvider);
- negotiator.setEncryptionAlgorithmName(algorithmName);
- return negotiator;
- }
-}
+/*
+ * 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.connector;
+
+import org.eclipse.net4j.util.security.INegotiatorAware;
+import org.eclipse.net4j.util.security.IPasswordCredentialsProvider;
+import org.eclipse.net4j.util.security.ResponseNegotiator;
+import org.eclipse.net4j.util.security.ResponseNegotiatorInjector;
+import org.eclipse.net4j.util.security.SecurityUtil;
+
+/**
+ * Injects a configurable response negotiator into selected client connectors.
+ * <p>
+ * An example:
+ *
+ * <pre>
+ * IManagedContainer container = IPluginContainer.INSTANCE;
+ *
+ * String connectorDescription = &quot;localhost:2036&quot;;
+ * String userID = &quot;name&quot;;
+ * String password = &quot;secret&quot;;
+ *
+ * IPasswordCredentialsProvider credentialsProvider = new PasswordCredentialsProvider(userID, password);
+ *
+ * container.addPostProcessor(new ConnectorCredentialsInjector(connectorDescription, credentialsProvider));
+ * IConnector connector = (IConnector)container.getElement(&quot;org.eclipse.net4j.connectors&quot;, &quot;tcp&quot;, connectorDescription);
+ *
+ * IChannel channel = connector.openChannel();
+ * // ...
+ * </pre>
+ *
+ * @author Eike Stepper
+ * @since 2.0
+ */
+public class ConnectorCredentialsInjector extends ResponseNegotiatorInjector
+{
+ private String connectorDescription;
+
+ /**
+ * @param connectorDescription
+ * The description of the IConnector that the negotiator shall be injected into, or <code>null</code> to
+ * bypass the description check.
+ */
+ public ConnectorCredentialsInjector(String connectorDescription, IPasswordCredentialsProvider credentialsProvider,
+ String algorithmName)
+ {
+ super(createNegotiator(credentialsProvider, algorithmName));
+ this.connectorDescription = connectorDescription;
+ }
+
+ /**
+ * @param connectorDescription
+ * The description of the IConnector that the negotiator shall be injected into, or <code>null</code> to
+ * bypass the description check.
+ */
+ public ConnectorCredentialsInjector(String connectorDescription, IPasswordCredentialsProvider credentialsProvider)
+ {
+ this(connectorDescription, credentialsProvider, SecurityUtil.PBE_WITH_MD5_AND_DES);
+ }
+
+ @Override
+ protected boolean filterElement(String productGroup, String factoryType, String description,
+ INegotiatorAware negotiatorAware)
+ {
+ if (negotiatorAware instanceof IConnector)
+ {
+ IConnector connector = (IConnector)negotiatorAware;
+ if (connector.isClient())
+ {
+ return filterConnectorDescription(description);
+ }
+ }
+
+ return false;
+ }
+
+ protected boolean filterConnectorDescription(String description)
+ {
+ if (connectorDescription == null)
+ {
+ return true;
+ }
+
+ return connectorDescription.equals(description);
+ }
+
+ private static ResponseNegotiator createNegotiator(IPasswordCredentialsProvider credentialsProvider,
+ String algorithmName)
+ {
+ ResponseNegotiator negotiator = new ResponseNegotiator();
+ negotiator.setCredentialsProvider(credentialsProvider);
+ negotiator.setEncryptionAlgorithmName(algorithmName);
+ return negotiator;
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/connector/ConnectorException.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/connector/ConnectorException.java
index 70fc99e921..042fb2bbf3 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/connector/ConnectorException.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/connector/ConnectorException.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.connector;
-
-/**
- * Thrown by an {@link IConnector} to indicate connection problems.
- *
- * @author Eike Stepper
- */
-public class ConnectorException extends RuntimeException
-{
- private static final long serialVersionUID = 1L;
-
- public ConnectorException()
- {
- }
-
- public ConnectorException(String message)
- {
- super(message);
- }
-
- public ConnectorException(Throwable cause)
- {
- super(cause);
- }
-
- public ConnectorException(String message, Throwable cause)
- {
- super(message, cause);
- }
-}
+/*
+ * 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.connector;
+
+/**
+ * Thrown by an {@link IConnector} to indicate connection problems.
+ *
+ * @author Eike Stepper
+ */
+public class ConnectorException extends RuntimeException
+{
+ private static final long serialVersionUID = 1L;
+
+ public ConnectorException()
+ {
+ }
+
+ public ConnectorException(String message)
+ {
+ super(message);
+ }
+
+ public ConnectorException(Throwable cause)
+ {
+ super(cause);
+ }
+
+ public ConnectorException(String message, Throwable cause)
+ {
+ super(message, cause);
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/connector/ConnectorState.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/connector/ConnectorState.java
index 11a570db59..86231c1a5f 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/connector/ConnectorState.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/connector/ConnectorState.java
@@ -1,92 +1,92 @@
-/*
- * 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.connector;
-
-import org.eclipse.net4j.util.security.INegotiator;
-
-/**
- * Enumerates the lifecycle states of an {@link IConnector}.
- * <p>
- * <dt><b>State Machine Diagram:</b></dt>
- * <dd><img src="doc-files/ConnectorState-1.gif" title="Diagram Connector States" border="0"
- * usemap="#ConnectorState-1.gif"/></dd>
- * <p>
- * <MAP NAME="ConnectorState-1.gif"> <AREA SHAPE="RECT" COORDS="26,135,143,159" HREF="ConnectorState.html#DISCONNECTED">
- * <AREA SHAPE="RECT" COORDS="449,50,547,73" HREF="ConnectorState.html#CONNECTING"> <AREA SHAPE="RECT"
- * COORDS="449,133,549,159" HREF="ConnectorState.html#NEGOTIATING"> <AREA SHAPE="RECT" COORDS="451,216,545,240"
- * HREF="ConnectorState.html#CONNECTED"> <AREA SHAPE="POLYGON" COORDS="10,89,11,183,164,183,163,109,77,109,77,89,11,88"
- * HREF="../util/lifecycle/ILifecycle.html#isActive()"> <AREA SHAPE="POLYGON"
- * COORDS="429,10,428,262,597,263,597,30,483,29,483,10,428,11" HREF="../util/lifecycle/ILifecycle.html#isActive()">
- * </MAP>
- *
- * @see IConnector#getState()
- * @author Eike Stepper
- * @noextend This interface is not intended to be extended by clients.
- */
-public enum ConnectorState
-{
- /**
- * Indicates that the {@link IConnector} has not been connected yet or has been disconnected after being connected
- * previously.
- * <p>
- * A connector is <code>DISCONNECTED</code> if and only if it is not
- * {@link org.eclipse.net4j.util.lifecycle.LifecycleUtil#isActive(Object) active}. A transition to {@link #CONNECTING}
- * can be triggered by calling {@link IConnector#connect(long)} or {@link IConnector#connectAsync()}.
- *
- * @see IConnector#getState()
- * @see org.eclipse.net4j.util.lifecycle.ILifecycle#isActive()
- */
- DISCONNECTED,
-
- /**
- * Indicates that the {@link IConnector} is currently trying to establish an underlying physical connection like a TCP
- * socket connection.
- * <p>
- * A connector can only be <code>CONNECTING</code> if it is
- * {@link org.eclipse.net4j.util.lifecycle.LifecycleUtil#isActive(Object) active}. As soon as the underlying physical
- * connection is successfully established the state of the connector automatically transitions to {@link #NEGOTIATING}.
- *
- * @see IConnector#getState()
- * @see org.eclipse.net4j.util.lifecycle.ILifecycle#isActive()
- */
- CONNECTING,
-
- /**
- * Indicates that the {@link IConnector} has successfully managed to establish the underlying physical connection and
- * has currently delegated control over this connection to an {@link INegotiator}.
- * <p>
- * A connector can only be <code>NEGOTIATING</code> if it is
- * {@link org.eclipse.net4j.util.lifecycle.LifecycleUtil#isActive(Object) active} and a negotiator has been supplied.
- * As soon as the negotiator has successfully negotiated both peers (or a negotiator has not been supplied) the state
- * of the connector automatically transitions to {@link #CONNECTED}.
- * <p>
- * Negotiators can implement arbitrary handshake protocols, challenge-response sequences or other authentication
- * procedures. They can also be used to initially setup connection encryption if the connector implementation is not
- * able to do so.
- *
- * @see IConnector#getState()
- * @see org.eclipse.net4j.util.lifecycle.ILifecycle#isActive()
- */
- NEGOTIATING,
-
- /**
- * Indicates that the {@link IConnector} has successfully managed to establish and negotiate the underlying physical
- * connection and is ready now to perform actual communications.
- * <p>
- * A connector can only be <code>CONNECTED</code> if it is
- * {@link org.eclipse.net4j.util.lifecycle.LifecycleUtil#isActive(Object) active}. A transition to
- * {@link #DISCONNECTED} can be triggered by calling {@link IConnector#close()}.
- *
- * @see IConnector#getState()
- * @see org.eclipse.net4j.util.lifecycle.ILifecycle#isActive()
- */
- CONNECTED
-}
+/*
+ * 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.connector;
+
+import org.eclipse.net4j.util.security.INegotiator;
+
+/**
+ * Enumerates the lifecycle states of an {@link IConnector}.
+ * <p>
+ * <dt><b>State Machine Diagram:</b></dt>
+ * <dd><img src="doc-files/ConnectorState-1.gif" title="Diagram Connector States" border="0"
+ * usemap="#ConnectorState-1.gif"/></dd>
+ * <p>
+ * <MAP NAME="ConnectorState-1.gif"> <AREA SHAPE="RECT" COORDS="26,135,143,159" HREF="ConnectorState.html#DISCONNECTED">
+ * <AREA SHAPE="RECT" COORDS="449,50,547,73" HREF="ConnectorState.html#CONNECTING"> <AREA SHAPE="RECT"
+ * COORDS="449,133,549,159" HREF="ConnectorState.html#NEGOTIATING"> <AREA SHAPE="RECT" COORDS="451,216,545,240"
+ * HREF="ConnectorState.html#CONNECTED"> <AREA SHAPE="POLYGON" COORDS="10,89,11,183,164,183,163,109,77,109,77,89,11,88"
+ * HREF="../util/lifecycle/ILifecycle.html#isActive()"> <AREA SHAPE="POLYGON"
+ * COORDS="429,10,428,262,597,263,597,30,483,29,483,10,428,11" HREF="../util/lifecycle/ILifecycle.html#isActive()">
+ * </MAP>
+ *
+ * @see IConnector#getState()
+ * @author Eike Stepper
+ * @noextend This interface is not intended to be extended by clients.
+ */
+public enum ConnectorState
+{
+ /**
+ * Indicates that the {@link IConnector} has not been connected yet or has been disconnected after being connected
+ * previously.
+ * <p>
+ * A connector is <code>DISCONNECTED</code> if and only if it is not
+ * {@link org.eclipse.net4j.util.lifecycle.LifecycleUtil#isActive(Object) active}. A transition to {@link #CONNECTING}
+ * can be triggered by calling {@link IConnector#connect(long)} or {@link IConnector#connectAsync()}.
+ *
+ * @see IConnector#getState()
+ * @see org.eclipse.net4j.util.lifecycle.ILifecycle#isActive()
+ */
+ DISCONNECTED,
+
+ /**
+ * Indicates that the {@link IConnector} is currently trying to establish an underlying physical connection like a TCP
+ * socket connection.
+ * <p>
+ * A connector can only be <code>CONNECTING</code> if it is
+ * {@link org.eclipse.net4j.util.lifecycle.LifecycleUtil#isActive(Object) active}. As soon as the underlying physical
+ * connection is successfully established the state of the connector automatically transitions to {@link #NEGOTIATING}.
+ *
+ * @see IConnector#getState()
+ * @see org.eclipse.net4j.util.lifecycle.ILifecycle#isActive()
+ */
+ CONNECTING,
+
+ /**
+ * Indicates that the {@link IConnector} has successfully managed to establish the underlying physical connection and
+ * has currently delegated control over this connection to an {@link INegotiator}.
+ * <p>
+ * A connector can only be <code>NEGOTIATING</code> if it is
+ * {@link org.eclipse.net4j.util.lifecycle.LifecycleUtil#isActive(Object) active} and a negotiator has been supplied.
+ * As soon as the negotiator has successfully negotiated both peers (or a negotiator has not been supplied) the state
+ * of the connector automatically transitions to {@link #CONNECTED}.
+ * <p>
+ * Negotiators can implement arbitrary handshake protocols, challenge-response sequences or other authentication
+ * procedures. They can also be used to initially setup connection encryption if the connector implementation is not
+ * able to do so.
+ *
+ * @see IConnector#getState()
+ * @see org.eclipse.net4j.util.lifecycle.ILifecycle#isActive()
+ */
+ NEGOTIATING,
+
+ /**
+ * Indicates that the {@link IConnector} has successfully managed to establish and negotiate the underlying physical
+ * connection and is ready now to perform actual communications.
+ * <p>
+ * A connector can only be <code>CONNECTED</code> if it is
+ * {@link org.eclipse.net4j.util.lifecycle.LifecycleUtil#isActive(Object) active}. A transition to
+ * {@link #DISCONNECTED} can be triggered by calling {@link IConnector#close()}.
+ *
+ * @see IConnector#getState()
+ * @see org.eclipse.net4j.util.lifecycle.ILifecycle#isActive()
+ */
+ CONNECTED
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/connector/IConnector.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/connector/IConnector.java
index 397e9978ea..123aaa2c8b 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/connector/IConnector.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/connector/IConnector.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.connector;
-
-import org.eclipse.net4j.buffer.IBuffer;
-import org.eclipse.net4j.channel.IChannel;
-import org.eclipse.net4j.channel.IChannelMultiplexer;
-import org.eclipse.net4j.util.collection.Closeable;
-import org.eclipse.net4j.util.security.IUserAware;
-
-/**
- * One endpoint of a physical connection of arbitrary nature between two communicating parties. A {@link IConnector}
- * encapsulates the process of establishing and closing such connections and has a
- * {@link org.eclipse.net4j.ILocationAware.Location location} of
- * {@link org.eclipse.net4j.ILocationAware.Location#CLIENT CLIENT} or
- * {@link org.eclipse.net4j.ILocationAware.Location#SERVER SERVER} with respect to this process. Once a connection is
- * established either party can use its connector to open multiple {@link IChannel}s to asynchronously exchange
- * {@link IBuffer}s.
- * <p>
- * This interface is <b>not</b> intended to be implemented by clients. Providers of connectors for new physical
- * connection types have to implement org.eclipse.internal.net4j.connector.InternalConnector.
- * <p>
- * <dt><b>Class Diagram:</b></dt>
- * <dd><img src="doc-files/IConnector-1.gif" title="Diagram Connectors" border="0" usemap="IConnector-1.gif"/></dd>
- * <p>
- * <MAP NAME="IConnector-1.gif"> <AREA SHAPE="RECT" COORDS="259,15,400,75" HREF="IConnectorCredentials.html"> <AREA
- * SHAPE="RECT" COORDS="12,174,138,245" HREF="ConnectorLocation.html"> <AREA SHAPE="RECT" COORDS="258,139,401,281"
- * HREF="IConnector.html"> <AREA SHAPE="RECT" COORDS="518,156,642,263" HREF="ConnectorState.html"> <AREA SHAPE="RECT"
- * COORDS="280,360,380,410" HREF="IChannel.html"> </MAP>
- * <p>
- * <dt><b>Sequence Diagram: Communication Process</b></dt>
- * <dd><img src="doc-files/IConnector-2.gif" title="Communication Process" border="0" usemap="#IConnector-2.gif"/></dd>
- * <p>
- * <MAP NAME="IConnector-2.gif"> <AREA SHAPE="RECT" COORDS="128,94,247,123" HREF="IConnector.html"> <AREA SHAPE="RECT"
- * COORDS="648,95,767,123" HREF="IConnector.html"> <AREA SHAPE="RECT" COORDS="509,254,608,283" HREF="IChannel.html">
- * <AREA SHAPE="RECT" COORDS="287,355,387,383" HREF="IChannel.html"> <AREA SHAPE="RECT" COORDS="818,195,897,222"
- * HREF="IProtocol.html"> </MAP>
- *
- * @author Eike Stepper
- * @noimplement This interface is not intended to be implemented by clients.
- */
-public interface IConnector extends IChannelMultiplexer, IUserAware, Closeable
-{
- /**
- * @since 2.0
- */
- public static final long NO_TIMEOUT = -1;
-
- public String getURL();
-
- /**
- * Returns the current state of this connector.
- */
- public ConnectorState getState();
-
- /**
- * Same as <code>{@link #getState()} == {@link ConnectorState#CONNECTED}</code>.
- */
- public boolean isConnected();
-
- /**
- * Synchronous connect with infinite timeout value. Same as {@link #connect() connect(NO_TIMEOUT)}.
- *
- * @throws ConnectorException
- * @since 4.0
- */
- public void connect() throws ConnectorException;
-
- /**
- * Synchronous connect. Blocks until <code>{@link #isConnected()} == true</code> or the given timeout expired.
- *
- * @param timeout
- * The maximum number of milli seconds to block or {@link #NO_TIMEOUT} to block indefinetely in case no
- * connection occurs.
- * @throws ConnectorException
- * @since 4.0
- */
- public void connect(long timeout) throws ConnectorException;
-
- /**
- * Asynchronous connect. May leave this {@link IConnector} in a state where <code>{@link #isConnected()} == false
- * </code>.
- *
- * @throws ConnectorException
- * @see #waitForConnection(long)
- * @see #connect(long)
- */
- public void connectAsync() throws ConnectorException;
-
- /**
- * Blocks until <code>{@link #isConnected()} == true</code> or the given timeout expired.
- *
- * @param timeout
- * The maximum number of milli seconds to block or {@link #NO_TIMEOUT} to block indefinetely in case no
- * connection occurs.
- * @throws ConnectorException
- * @since 4.0
- */
- public void waitForConnection(long timeout) throws ConnectorException;
-}
+/*
+ * 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.connector;
+
+import org.eclipse.net4j.buffer.IBuffer;
+import org.eclipse.net4j.channel.IChannel;
+import org.eclipse.net4j.channel.IChannelMultiplexer;
+import org.eclipse.net4j.util.collection.Closeable;
+import org.eclipse.net4j.util.security.IUserAware;
+
+/**
+ * One endpoint of a physical connection of arbitrary nature between two communicating parties. A {@link IConnector}
+ * encapsulates the process of establishing and closing such connections and has a
+ * {@link org.eclipse.net4j.ILocationAware.Location location} of
+ * {@link org.eclipse.net4j.ILocationAware.Location#CLIENT CLIENT} or
+ * {@link org.eclipse.net4j.ILocationAware.Location#SERVER SERVER} with respect to this process. Once a connection is
+ * established either party can use its connector to open multiple {@link IChannel}s to asynchronously exchange
+ * {@link IBuffer}s.
+ * <p>
+ * This interface is <b>not</b> intended to be implemented by clients. Providers of connectors for new physical
+ * connection types have to implement org.eclipse.internal.net4j.connector.InternalConnector.
+ * <p>
+ * <dt><b>Class Diagram:</b></dt>
+ * <dd><img src="doc-files/IConnector-1.gif" title="Diagram Connectors" border="0" usemap="IConnector-1.gif"/></dd>
+ * <p>
+ * <MAP NAME="IConnector-1.gif"> <AREA SHAPE="RECT" COORDS="259,15,400,75" HREF="IConnectorCredentials.html"> <AREA
+ * SHAPE="RECT" COORDS="12,174,138,245" HREF="ConnectorLocation.html"> <AREA SHAPE="RECT" COORDS="258,139,401,281"
+ * HREF="IConnector.html"> <AREA SHAPE="RECT" COORDS="518,156,642,263" HREF="ConnectorState.html"> <AREA SHAPE="RECT"
+ * COORDS="280,360,380,410" HREF="IChannel.html"> </MAP>
+ * <p>
+ * <dt><b>Sequence Diagram: Communication Process</b></dt>
+ * <dd><img src="doc-files/IConnector-2.gif" title="Communication Process" border="0" usemap="#IConnector-2.gif"/></dd>
+ * <p>
+ * <MAP NAME="IConnector-2.gif"> <AREA SHAPE="RECT" COORDS="128,94,247,123" HREF="IConnector.html"> <AREA SHAPE="RECT"
+ * COORDS="648,95,767,123" HREF="IConnector.html"> <AREA SHAPE="RECT" COORDS="509,254,608,283" HREF="IChannel.html">
+ * <AREA SHAPE="RECT" COORDS="287,355,387,383" HREF="IChannel.html"> <AREA SHAPE="RECT" COORDS="818,195,897,222"
+ * HREF="IProtocol.html"> </MAP>
+ *
+ * @author Eike Stepper
+ * @noimplement This interface is not intended to be implemented by clients.
+ */
+public interface IConnector extends IChannelMultiplexer, IUserAware, Closeable
+{
+ /**
+ * @since 2.0
+ */
+ public static final long NO_TIMEOUT = -1;
+
+ public String getURL();
+
+ /**
+ * Returns the current state of this connector.
+ */
+ public ConnectorState getState();
+
+ /**
+ * Same as <code>{@link #getState()} == {@link ConnectorState#CONNECTED}</code>.
+ */
+ public boolean isConnected();
+
+ /**
+ * Synchronous connect with infinite timeout value. Same as {@link #connect() connect(NO_TIMEOUT)}.
+ *
+ * @throws ConnectorException
+ * @since 4.0
+ */
+ public void connect() throws ConnectorException;
+
+ /**
+ * Synchronous connect. Blocks until <code>{@link #isConnected()} == true</code> or the given timeout expired.
+ *
+ * @param timeout
+ * The maximum number of milli seconds to block or {@link #NO_TIMEOUT} to block indefinetely in case no
+ * connection occurs.
+ * @throws ConnectorException
+ * @since 4.0
+ */
+ public void connect(long timeout) throws ConnectorException;
+
+ /**
+ * Asynchronous connect. May leave this {@link IConnector} in a state where <code>{@link #isConnected()} == false
+ * </code>.
+ *
+ * @throws ConnectorException
+ * @see #waitForConnection(long)
+ * @see #connect(long)
+ */
+ public void connectAsync() throws ConnectorException;
+
+ /**
+ * Blocks until <code>{@link #isConnected()} == true</code> or the given timeout expired.
+ *
+ * @param timeout
+ * The maximum number of milli seconds to block or {@link #NO_TIMEOUT} to block indefinetely in case no
+ * connection occurs.
+ * @throws ConnectorException
+ * @since 4.0
+ */
+ public void waitForConnection(long timeout) throws ConnectorException;
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/connector/IConnectorEvent.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/connector/IConnectorEvent.java
index 2c98d66356..14220aa95e 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/connector/IConnectorEvent.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/connector/IConnectorEvent.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.connector;
-
-import org.eclipse.net4j.util.container.IContainerEvent;
-import org.eclipse.net4j.util.event.IEvent;
-
-/**
- * A generic {@link IEvent event} fired from a {@link IConnector connector}.
- *
- * @author Eike Stepper
- * @noextend This interface is not intended to be extended by clients.
- * @noimplement This interface is not intended to be implemented by clients.
- */
-public interface IConnectorEvent extends IEvent
-{
- /**
- * The {@link IConnector} that sent this event.
- *
- * @see IContainerEvent#getSource()
- * @since 3.0
- */
- public IConnector getSource();
-}
+/*
+ * 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.connector;
+
+import org.eclipse.net4j.util.container.IContainerEvent;
+import org.eclipse.net4j.util.event.IEvent;
+
+/**
+ * A generic {@link IEvent event} fired from a {@link IConnector connector}.
+ *
+ * @author Eike Stepper
+ * @noextend This interface is not intended to be extended by clients.
+ * @noimplement This interface is not intended to be implemented by clients.
+ */
+public interface IConnectorEvent extends IEvent
+{
+ /**
+ * The {@link IConnector} that sent this event.
+ *
+ * @see IContainerEvent#getSource()
+ * @since 3.0
+ */
+ public IConnector getSource();
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/connector/IConnectorStateEvent.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/connector/IConnectorStateEvent.java
index 76cf11b404..9e32994f9c 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/connector/IConnectorStateEvent.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/connector/IConnectorStateEvent.java
@@ -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
- */
-package org.eclipse.net4j.connector;
-
-/**
- * An event that is fired by an {@link IConnector} to indicate that its state has changed.
- *
- * @author Eike Stepper
- * @noextend This interface is not intended to be extended by clients.
- * @noimplement This interface is not intended to be implemented by clients.
- */
-public interface IConnectorStateEvent extends IConnectorEvent
-{
- /**
- * The old state of the {@link IConnector} that sent this event.
- */
- public ConnectorState getOldState();
-
- /**
- * The new state of the {@link IConnector} that sent this event.
- */
- public ConnectorState getNewState();
-}
+/*
+ * 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.connector;
+
+/**
+ * An event that is fired by an {@link IConnector} to indicate that its state has changed.
+ *
+ * @author Eike Stepper
+ * @noextend This interface is not intended to be extended by clients.
+ * @noimplement This interface is not intended to be implemented by clients.
+ */
+public interface IConnectorStateEvent extends IConnectorEvent
+{
+ /**
+ * The old state of the {@link IConnector} that sent this event.
+ */
+ public ConnectorState getOldState();
+
+ /**
+ * The new state of the {@link IConnector} that sent this event.
+ */
+ public ConnectorState getNewState();
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/connector/package-info.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/connector/package-info.java
index 69999df8bc..aa7dd0a97b 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/connector/package-info.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/connector/package-info.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
+ * 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
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/package-info.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/package-info.java
index 5133f07249..13356f72d0 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/package-info.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/package-info.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
+ * 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
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/protocol/IProtocol.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/protocol/IProtocol.java
index 0465b932e5..882111c565 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/protocol/IProtocol.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/protocol/IProtocol.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.protocol;
-
-import org.eclipse.net4j.ILocationAware;
-import org.eclipse.net4j.buffer.IBufferHandler;
-import org.eclipse.net4j.buffer.IBufferProvider;
-import org.eclipse.net4j.channel.IChannel;
-import org.eclipse.net4j.util.security.IUserAware;
-
-import java.util.concurrent.ExecutorService;
-
-/**
- * @author Eike Stepper
- */
-public interface IProtocol<INFRA_STRUCTURE> extends IUserAware, ILocationAware, IBufferHandler
-{
- public String getType();
-
- public IChannel getChannel();
-
- public void setChannel(IChannel channel);
-
- public INFRA_STRUCTURE getInfraStructure();
-
- public void setInfraStructure(INFRA_STRUCTURE infraStructure);
-
- public IBufferProvider getBufferProvider();
-
- public ExecutorService getExecutorService();
-
- public void setExecutorService(ExecutorService executorService);
-}
+/*
+ * 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.protocol;
+
+import org.eclipse.net4j.ILocationAware;
+import org.eclipse.net4j.buffer.IBufferHandler;
+import org.eclipse.net4j.buffer.IBufferProvider;
+import org.eclipse.net4j.channel.IChannel;
+import org.eclipse.net4j.util.security.IUserAware;
+
+import java.util.concurrent.ExecutorService;
+
+/**
+ * @author Eike Stepper
+ */
+public interface IProtocol<INFRA_STRUCTURE> extends IUserAware, ILocationAware, IBufferHandler
+{
+ public String getType();
+
+ public IChannel getChannel();
+
+ public void setChannel(IChannel channel);
+
+ public INFRA_STRUCTURE getInfraStructure();
+
+ public void setInfraStructure(INFRA_STRUCTURE infraStructure);
+
+ public IBufferProvider getBufferProvider();
+
+ public ExecutorService getExecutorService();
+
+ public void setExecutorService(ExecutorService executorService);
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/protocol/IProtocolProvider.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/protocol/IProtocolProvider.java
index a0a11b4233..ce7ecd9b0e 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/protocol/IProtocolProvider.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/protocol/IProtocolProvider.java
@@ -1,22 +1,22 @@
-/*
- * 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.protocol;
-
-/**
- * @author Eike Stepper
- */
-public interface IProtocolProvider
-{
- /**
- * @since 2.0
- */
- public IProtocol<?> getProtocol(String type);
-}
+/*
+ * 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.protocol;
+
+/**
+ * @author Eike Stepper
+ */
+public interface IProtocolProvider
+{
+ /**
+ * @since 2.0
+ */
+ public IProtocol<?> getProtocol(String type);
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/protocol/package-info.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/protocol/package-info.java
index a5951f5999..b68bc1d0e6 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/protocol/package-info.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/protocol/package-info.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
+ * 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
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/ISignalProtocol.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/ISignalProtocol.java
index 6ed4b418f2..32737022b8 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/ISignalProtocol.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/ISignalProtocol.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.signal;
-
-import org.eclipse.net4j.buffer.BufferInputStream;
-import org.eclipse.net4j.channel.IChannel;
-import org.eclipse.net4j.connector.IConnector;
-import org.eclipse.net4j.protocol.IProtocol;
-import org.eclipse.net4j.util.event.INotifier;
-import org.eclipse.net4j.util.io.IStreamWrapper;
-
-/**
- * @author Eike Stepper
- * @since 2.0
- */
-public interface ISignalProtocol<INFRA_STRUCTURE> extends IProtocol<INFRA_STRUCTURE>, INotifier
-{
- public static final long NO_TIMEOUT = BufferInputStream.NO_TIMEOUT;
-
- public static final long DEFAULT_TIMEOUT = 10 * 1000L;
-
- public long getTimeout();
-
- public void setTimeout(long timeout);
-
- public IStreamWrapper getStreamWrapper();
-
- public void setStreamWrapper(IStreamWrapper streamWrapper);
-
- public void addStreamWrapper(IStreamWrapper streamWrapper);
-
- public IChannel open(IConnector connector);
-
- public void 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.signal;
+
+import org.eclipse.net4j.buffer.BufferInputStream;
+import org.eclipse.net4j.channel.IChannel;
+import org.eclipse.net4j.connector.IConnector;
+import org.eclipse.net4j.protocol.IProtocol;
+import org.eclipse.net4j.util.event.INotifier;
+import org.eclipse.net4j.util.io.IStreamWrapper;
+
+/**
+ * @author Eike Stepper
+ * @since 2.0
+ */
+public interface ISignalProtocol<INFRA_STRUCTURE> extends IProtocol<INFRA_STRUCTURE>, INotifier
+{
+ public static final long NO_TIMEOUT = BufferInputStream.NO_TIMEOUT;
+
+ public static final long DEFAULT_TIMEOUT = 10 * 1000L;
+
+ public long getTimeout();
+
+ public void setTimeout(long timeout);
+
+ public IStreamWrapper getStreamWrapper();
+
+ public void setStreamWrapper(IStreamWrapper streamWrapper);
+
+ public void addStreamWrapper(IStreamWrapper streamWrapper);
+
+ public IChannel open(IConnector connector);
+
+ public void close();
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/Indication.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/Indication.java
index 2c82e8e7bf..756526aad9 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/Indication.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/Indication.java
@@ -1,59 +1,59 @@
-/*
- * 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.signal;
-
-import org.eclipse.net4j.buffer.BufferInputStream;
-import org.eclipse.net4j.buffer.BufferOutputStream;
-import org.eclipse.net4j.util.io.ExtendedDataInputStream;
-
-/**
- * @author Eike Stepper
- */
-public abstract class Indication extends SignalReactor
-{
- /**
- * @since 2.0
- */
- public Indication(SignalProtocol<?> protocol, short id, String name)
- {
- super(protocol, id, name);
- }
-
- /**
- * @since 2.0
- */
- public Indication(SignalProtocol<?> protocol, short signalID)
- {
- super(protocol, signalID);
- }
-
- /**
- * @since 2.0
- */
- public Indication(SignalProtocol<?> protocol, Enum<?> literal)
- {
- super(protocol, literal);
- }
-
- @Override
- protected void execute(BufferInputStream in, BufferOutputStream out) throws Exception
- {
- doInput(in);
- }
-
- @Override
- void doExtendedInput(ExtendedDataInputStream in) throws Exception
- {
- indicating(in);
- }
-
- protected abstract void indicating(ExtendedDataInputStream in) throws 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.signal;
+
+import org.eclipse.net4j.buffer.BufferInputStream;
+import org.eclipse.net4j.buffer.BufferOutputStream;
+import org.eclipse.net4j.util.io.ExtendedDataInputStream;
+
+/**
+ * @author Eike Stepper
+ */
+public abstract class Indication extends SignalReactor
+{
+ /**
+ * @since 2.0
+ */
+ public Indication(SignalProtocol<?> protocol, short id, String name)
+ {
+ super(protocol, id, name);
+ }
+
+ /**
+ * @since 2.0
+ */
+ public Indication(SignalProtocol<?> protocol, short signalID)
+ {
+ super(protocol, signalID);
+ }
+
+ /**
+ * @since 2.0
+ */
+ public Indication(SignalProtocol<?> protocol, Enum<?> literal)
+ {
+ super(protocol, literal);
+ }
+
+ @Override
+ protected void execute(BufferInputStream in, BufferOutputStream out) throws Exception
+ {
+ doInput(in);
+ }
+
+ @Override
+ void doExtendedInput(ExtendedDataInputStream in) throws Exception
+ {
+ indicating(in);
+ }
+
+ protected abstract void indicating(ExtendedDataInputStream in) throws Exception;
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/IndicationWithMonitoring.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/IndicationWithMonitoring.java
index 19eb79402d..6241a29522 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/IndicationWithMonitoring.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/IndicationWithMonitoring.java
@@ -1,172 +1,172 @@
-/*
- * 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.signal;
-
-import org.eclipse.net4j.buffer.BufferInputStream;
-import org.eclipse.net4j.buffer.BufferOutputStream;
-import org.eclipse.net4j.util.io.ExtendedDataInputStream;
-import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
-import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
-import org.eclipse.net4j.util.om.monitor.OMMonitor;
-import org.eclipse.net4j.util.om.monitor.TimeoutMonitor;
-
-import org.eclipse.internal.net4j.bundle.OM;
-
-import java.util.TimerTask;
-import java.util.concurrent.ExecutorService;
-
-/**
- * @author Eike Stepper
- * @since 2.0
- */
-public abstract class IndicationWithMonitoring extends IndicationWithResponse
-{
- private ReportingMonitor monitor;
-
- /**
- * @since 2.0
- */
- public IndicationWithMonitoring(SignalProtocol<?> protocol, short id, String name)
- {
- super(protocol, id, name);
- }
-
- /**
- * @since 2.0
- */
- public IndicationWithMonitoring(SignalProtocol<?> protocol, short signalID)
- {
- super(protocol, signalID);
- }
-
- /**
- * @since 2.0
- */
- public IndicationWithMonitoring(SignalProtocol<?> protocol, Enum<?> literal)
- {
- super(protocol, literal);
- }
-
- @Override
- protected void execute(BufferInputStream in, BufferOutputStream out) throws Exception
- {
- try
- {
- super.execute(in, out);
- }
- finally
- {
- if (monitor != null)
- {
- monitor.done();
- monitor = null;
- }
- }
- }
-
- @Override
- protected final void indicating(ExtendedDataInputStream in) throws Exception
- {
- int monitorProgressSeconds = in.readInt();
- int monitorTimeoutSeconds = in.readInt();
-
- monitor = new ReportingMonitor(monitorProgressSeconds, monitorTimeoutSeconds);
- monitor.begin(OMMonitor.HUNDRED);
-
- indicating(in, monitor.fork(getIndicatingWorkPercent()));
- }
-
- @Override
- protected final void responding(ExtendedDataOutputStream out) throws Exception
- {
- responding(out, monitor.fork(OMMonitor.HUNDRED - getIndicatingWorkPercent()));
- }
-
- protected abstract void indicating(ExtendedDataInputStream in, OMMonitor monitor) throws Exception;
-
- protected abstract void responding(ExtendedDataOutputStream out, OMMonitor monitor) throws Exception;
-
- /**
- * @since 2.0
- */
- protected ExecutorService getMonitoringExecutorService()
- {
- return getProtocol().getExecutorService();
- }
-
- protected int getIndicatingWorkPercent()
- {
- return 99;
- }
-
- void setMonitorCanceled()
- {
- monitor.cancel();
- }
-
- /**
- * @author Eike Stepper
- */
- private final class ReportingMonitor extends TimeoutMonitor
- {
- private TimerTask sendProgressTask = new TimerTask()
- {
- @Override
- public void run()
- {
- try
- {
- sendProgress();
- }
- catch (Exception ex)
- {
- OM.LOG.error("ReportingMonitorTask failed", ex);
- }
- }
- };
-
- public ReportingMonitor(int monitorProgressSeconds, int monitorTimeoutSeconds)
- {
- super(1000L * monitorTimeoutSeconds);
- long period = 1000L * monitorProgressSeconds;
- scheduleAtFixedRate(sendProgressTask, period, period);
- }
-
- @Override
- public void cancel(RuntimeException cancelException)
- {
- sendProgressTask.cancel();
- super.cancel(cancelException);
- }
-
- @Override
- public void done()
- {
- sendProgressTask.cancel();
- super.done();
- }
-
- private void sendProgress()
- {
- try
- {
- new MonitorProgressRequest(getProtocol(), -getCorrelationID(), getTotalWork(), getWork()).sendAsync();
- }
- catch (Exception ex)
- {
- if (LifecycleUtil.isActive(getProtocol().getChannel()))
- {
- OM.LOG.error(ex);
- }
- }
- }
- }
-}
+/*
+ * 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.signal;
+
+import org.eclipse.net4j.buffer.BufferInputStream;
+import org.eclipse.net4j.buffer.BufferOutputStream;
+import org.eclipse.net4j.util.io.ExtendedDataInputStream;
+import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
+import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
+import org.eclipse.net4j.util.om.monitor.OMMonitor;
+import org.eclipse.net4j.util.om.monitor.TimeoutMonitor;
+
+import org.eclipse.internal.net4j.bundle.OM;
+
+import java.util.TimerTask;
+import java.util.concurrent.ExecutorService;
+
+/**
+ * @author Eike Stepper
+ * @since 2.0
+ */
+public abstract class IndicationWithMonitoring extends IndicationWithResponse
+{
+ private ReportingMonitor monitor;
+
+ /**
+ * @since 2.0
+ */
+ public IndicationWithMonitoring(SignalProtocol<?> protocol, short id, String name)
+ {
+ super(protocol, id, name);
+ }
+
+ /**
+ * @since 2.0
+ */
+ public IndicationWithMonitoring(SignalProtocol<?> protocol, short signalID)
+ {
+ super(protocol, signalID);
+ }
+
+ /**
+ * @since 2.0
+ */
+ public IndicationWithMonitoring(SignalProtocol<?> protocol, Enum<?> literal)
+ {
+ super(protocol, literal);
+ }
+
+ @Override
+ protected void execute(BufferInputStream in, BufferOutputStream out) throws Exception
+ {
+ try
+ {
+ super.execute(in, out);
+ }
+ finally
+ {
+ if (monitor != null)
+ {
+ monitor.done();
+ monitor = null;
+ }
+ }
+ }
+
+ @Override
+ protected final void indicating(ExtendedDataInputStream in) throws Exception
+ {
+ int monitorProgressSeconds = in.readInt();
+ int monitorTimeoutSeconds = in.readInt();
+
+ monitor = new ReportingMonitor(monitorProgressSeconds, monitorTimeoutSeconds);
+ monitor.begin(OMMonitor.HUNDRED);
+
+ indicating(in, monitor.fork(getIndicatingWorkPercent()));
+ }
+
+ @Override
+ protected final void responding(ExtendedDataOutputStream out) throws Exception
+ {
+ responding(out, monitor.fork(OMMonitor.HUNDRED - getIndicatingWorkPercent()));
+ }
+
+ protected abstract void indicating(ExtendedDataInputStream in, OMMonitor monitor) throws Exception;
+
+ protected abstract void responding(ExtendedDataOutputStream out, OMMonitor monitor) throws Exception;
+
+ /**
+ * @since 2.0
+ */
+ protected ExecutorService getMonitoringExecutorService()
+ {
+ return getProtocol().getExecutorService();
+ }
+
+ protected int getIndicatingWorkPercent()
+ {
+ return 99;
+ }
+
+ void setMonitorCanceled()
+ {
+ monitor.cancel();
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ private final class ReportingMonitor extends TimeoutMonitor
+ {
+ private TimerTask sendProgressTask = new TimerTask()
+ {
+ @Override
+ public void run()
+ {
+ try
+ {
+ sendProgress();
+ }
+ catch (Exception ex)
+ {
+ OM.LOG.error("ReportingMonitorTask failed", ex);
+ }
+ }
+ };
+
+ public ReportingMonitor(int monitorProgressSeconds, int monitorTimeoutSeconds)
+ {
+ super(1000L * monitorTimeoutSeconds);
+ long period = 1000L * monitorProgressSeconds;
+ scheduleAtFixedRate(sendProgressTask, period, period);
+ }
+
+ @Override
+ public void cancel(RuntimeException cancelException)
+ {
+ sendProgressTask.cancel();
+ super.cancel(cancelException);
+ }
+
+ @Override
+ public void done()
+ {
+ sendProgressTask.cancel();
+ super.done();
+ }
+
+ private void sendProgress()
+ {
+ try
+ {
+ new MonitorProgressRequest(getProtocol(), -getCorrelationID(), getTotalWork(), getWork()).sendAsync();
+ }
+ catch (Exception ex)
+ {
+ if (LifecycleUtil.isActive(getProtocol().getChannel()))
+ {
+ OM.LOG.error(ex);
+ }
+ }
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/IndicationWithResponse.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/IndicationWithResponse.java
index 383cc95640..209f2f1bd3 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/IndicationWithResponse.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/IndicationWithResponse.java
@@ -1,106 +1,106 @@
-/*
- * 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.signal;
-
-import org.eclipse.net4j.buffer.BufferInputStream;
-import org.eclipse.net4j.buffer.BufferOutputStream;
-import org.eclipse.net4j.util.StringUtil;
-import org.eclipse.net4j.util.io.ExtendedDataInputStream;
-import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
-
-/**
- * @author Eike Stepper
- */
-public abstract class IndicationWithResponse extends SignalReactor
-{
- /**
- * @since 2.0
- */
- public IndicationWithResponse(SignalProtocol<?> protocol, short id, String name)
- {
- super(protocol, id, name);
- }
-
- /**
- * @since 2.0
- */
- public IndicationWithResponse(SignalProtocol<?> protocol, short signalID)
- {
- super(protocol, signalID);
- }
-
- /**
- * @since 2.0
- */
- public IndicationWithResponse(SignalProtocol<?> protocol, Enum<?> literal)
- {
- super(protocol, literal);
- }
-
- /**
- * @since 2.0
- */
- protected String getExceptionMessage(Throwable t)
- {
- return StringUtil.formatException(t);
- }
-
- @Override
- protected void execute(BufferInputStream in, BufferOutputStream out) throws Exception
- {
- boolean responding = false;
-
- try
- {
- doInput(in);
- responding = true;
- doOutput(out);
- }
- catch (Error ex)
- {
- sendExceptionSignal(ex, responding);
- throw ex;
- }
- catch (Exception ex)
- {
- sendExceptionSignal(ex, responding);
- throw ex;
- }
- }
-
- protected abstract void indicating(ExtendedDataInputStream in) throws Exception;
-
- /**
- * <b>Important Note:</b> The response must not be empty, i.e. the stream must be used at least to write a
- * <code>boolean</code>. Otherwise synchronization problems will result!
- */
- protected abstract void responding(ExtendedDataOutputStream out) throws Exception;
-
- @Override
- void doExtendedInput(ExtendedDataInputStream in) throws Exception
- {
- indicating(in);
- }
-
- @Override
- void doExtendedOutput(ExtendedDataOutputStream out) throws Exception
- {
- responding(out);
- }
-
- void sendExceptionSignal(Throwable t, boolean responding) throws Exception
- {
- SignalProtocol<?> protocol = getProtocol();
- int correlationID = -getCorrelationID();
- String message = getExceptionMessage(t);
- new RemoteExceptionRequest(protocol, correlationID, responding, message, t).sendAsync();
- }
-}
+/*
+ * 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.signal;
+
+import org.eclipse.net4j.buffer.BufferInputStream;
+import org.eclipse.net4j.buffer.BufferOutputStream;
+import org.eclipse.net4j.util.StringUtil;
+import org.eclipse.net4j.util.io.ExtendedDataInputStream;
+import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
+
+/**
+ * @author Eike Stepper
+ */
+public abstract class IndicationWithResponse extends SignalReactor
+{
+ /**
+ * @since 2.0
+ */
+ public IndicationWithResponse(SignalProtocol<?> protocol, short id, String name)
+ {
+ super(protocol, id, name);
+ }
+
+ /**
+ * @since 2.0
+ */
+ public IndicationWithResponse(SignalProtocol<?> protocol, short signalID)
+ {
+ super(protocol, signalID);
+ }
+
+ /**
+ * @since 2.0
+ */
+ public IndicationWithResponse(SignalProtocol<?> protocol, Enum<?> literal)
+ {
+ super(protocol, literal);
+ }
+
+ /**
+ * @since 2.0
+ */
+ protected String getExceptionMessage(Throwable t)
+ {
+ return StringUtil.formatException(t);
+ }
+
+ @Override
+ protected void execute(BufferInputStream in, BufferOutputStream out) throws Exception
+ {
+ boolean responding = false;
+
+ try
+ {
+ doInput(in);
+ responding = true;
+ doOutput(out);
+ }
+ catch (Error ex)
+ {
+ sendExceptionSignal(ex, responding);
+ throw ex;
+ }
+ catch (Exception ex)
+ {
+ sendExceptionSignal(ex, responding);
+ throw ex;
+ }
+ }
+
+ protected abstract void indicating(ExtendedDataInputStream in) throws Exception;
+
+ /**
+ * <b>Important Note:</b> The response must not be empty, i.e. the stream must be used at least to write a
+ * <code>boolean</code>. Otherwise synchronization problems will result!
+ */
+ protected abstract void responding(ExtendedDataOutputStream out) throws Exception;
+
+ @Override
+ void doExtendedInput(ExtendedDataInputStream in) throws Exception
+ {
+ indicating(in);
+ }
+
+ @Override
+ void doExtendedOutput(ExtendedDataOutputStream out) throws Exception
+ {
+ responding(out);
+ }
+
+ void sendExceptionSignal(Throwable t, boolean responding) throws Exception
+ {
+ SignalProtocol<?> protocol = getProtocol();
+ int correlationID = -getCorrelationID();
+ String message = getExceptionMessage(t);
+ new RemoteExceptionRequest(protocol, correlationID, responding, message, t).sendAsync();
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/MonitorCanceledIndication.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/MonitorCanceledIndication.java
index bf60006819..074b459c8f 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/MonitorCanceledIndication.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/MonitorCanceledIndication.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.signal;
-
-import org.eclipse.net4j.util.io.ExtendedDataInputStream;
-import org.eclipse.net4j.util.om.trace.ContextTracer;
-
-import org.eclipse.internal.net4j.bundle.OM;
-
-/**
- * @author Eike Stepper
- */
-class MonitorCanceledIndication extends Indication
-{
- private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_SIGNAL, MonitorCanceledIndication.class);
-
- public MonitorCanceledIndication(SignalProtocol<?> protocol)
- {
- super(protocol, SignalProtocol.SIGNAL_MONITOR_CANCELED);
- }
-
- @Override
- protected void indicating(ExtendedDataInputStream in) throws Exception
- {
- int correlationID = in.readInt();
- if (TRACER.isEnabled())
- {
- TRACER.format("Canceling monitor of signal {0}", correlationID); //$NON-NLS-1$
- }
-
- getProtocol().handleMonitorCanceled(correlationID);
- }
-}
+/*
+ * 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.signal;
+
+import org.eclipse.net4j.util.io.ExtendedDataInputStream;
+import org.eclipse.net4j.util.om.trace.ContextTracer;
+
+import org.eclipse.internal.net4j.bundle.OM;
+
+/**
+ * @author Eike Stepper
+ */
+class MonitorCanceledIndication extends Indication
+{
+ private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_SIGNAL, MonitorCanceledIndication.class);
+
+ public MonitorCanceledIndication(SignalProtocol<?> protocol)
+ {
+ super(protocol, SignalProtocol.SIGNAL_MONITOR_CANCELED);
+ }
+
+ @Override
+ protected void indicating(ExtendedDataInputStream in) throws Exception
+ {
+ int correlationID = in.readInt();
+ if (TRACER.isEnabled())
+ {
+ TRACER.format("Canceling monitor of signal {0}", correlationID); //$NON-NLS-1$
+ }
+
+ getProtocol().handleMonitorCanceled(correlationID);
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/MonitorCanceledRequest.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/MonitorCanceledRequest.java
index c6529f81f9..e884c75720 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/MonitorCanceledRequest.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/MonitorCanceledRequest.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.signal;
-
-import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
-import org.eclipse.net4j.util.om.trace.ContextTracer;
-
-import org.eclipse.internal.net4j.bundle.OM;
-
-/**
- * @author Eike Stepper
- */
-class MonitorCanceledRequest extends Request
-{
- private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_SIGNAL, MonitorCanceledRequest.class);
-
- private int correlationID;
-
- public MonitorCanceledRequest(SignalProtocol<?> protocol, int correlationID)
- {
- super(protocol, SignalProtocol.SIGNAL_MONITOR_CANCELED);
- this.correlationID = correlationID;
- }
-
- @Override
- protected void requesting(ExtendedDataOutputStream out) throws Exception
- {
- if (TRACER.isEnabled())
- {
- TRACER.format("Canceling monitor of signal {0}", correlationID); //$NON-NLS-1$
- }
-
- out.writeInt(correlationID);
- }
-}
+/*
+ * 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.signal;
+
+import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
+import org.eclipse.net4j.util.om.trace.ContextTracer;
+
+import org.eclipse.internal.net4j.bundle.OM;
+
+/**
+ * @author Eike Stepper
+ */
+class MonitorCanceledRequest extends Request
+{
+ private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_SIGNAL, MonitorCanceledRequest.class);
+
+ private int correlationID;
+
+ public MonitorCanceledRequest(SignalProtocol<?> protocol, int correlationID)
+ {
+ super(protocol, SignalProtocol.SIGNAL_MONITOR_CANCELED);
+ this.correlationID = correlationID;
+ }
+
+ @Override
+ protected void requesting(ExtendedDataOutputStream out) throws Exception
+ {
+ if (TRACER.isEnabled())
+ {
+ TRACER.format("Canceling monitor of signal {0}", correlationID); //$NON-NLS-1$
+ }
+
+ out.writeInt(correlationID);
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/MonitorProgressIndication.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/MonitorProgressIndication.java
index 9f16979690..8a5ebff093 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/MonitorProgressIndication.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/MonitorProgressIndication.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.signal;
-
-import org.eclipse.net4j.util.io.ExtendedDataInputStream;
-import org.eclipse.net4j.util.om.trace.ContextTracer;
-
-import org.eclipse.internal.net4j.bundle.OM;
-
-/**
- * @author Eike Stepper
- */
-class MonitorProgressIndication extends Indication
-{
- private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_SIGNAL, MonitorProgressIndication.class);
-
- public MonitorProgressIndication(SignalProtocol<?> protocol)
- {
- super(protocol, SignalProtocol.SIGNAL_MONITOR_PROGRESS);
- }
-
- @Override
- protected void indicating(ExtendedDataInputStream in) throws Exception
- {
- int correlationID = in.readInt();
- double totalWork = in.readDouble();
- double work = in.readDouble();
- if (TRACER.isEnabled())
- {
- TRACER.format("Progress of signal {0}: totalWork={1}, work={2}", correlationID, totalWork, work); //$NON-NLS-1$
- }
-
- getProtocol().handleMonitorProgress(correlationID, totalWork, work);
- }
-}
+/*
+ * 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.signal;
+
+import org.eclipse.net4j.util.io.ExtendedDataInputStream;
+import org.eclipse.net4j.util.om.trace.ContextTracer;
+
+import org.eclipse.internal.net4j.bundle.OM;
+
+/**
+ * @author Eike Stepper
+ */
+class MonitorProgressIndication extends Indication
+{
+ private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_SIGNAL, MonitorProgressIndication.class);
+
+ public MonitorProgressIndication(SignalProtocol<?> protocol)
+ {
+ super(protocol, SignalProtocol.SIGNAL_MONITOR_PROGRESS);
+ }
+
+ @Override
+ protected void indicating(ExtendedDataInputStream in) throws Exception
+ {
+ int correlationID = in.readInt();
+ double totalWork = in.readDouble();
+ double work = in.readDouble();
+ if (TRACER.isEnabled())
+ {
+ TRACER.format("Progress of signal {0}: totalWork={1}, work={2}", correlationID, totalWork, work); //$NON-NLS-1$
+ }
+
+ getProtocol().handleMonitorProgress(correlationID, totalWork, work);
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/MonitorProgressRequest.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/MonitorProgressRequest.java
index ac3b2c1cbc..e80399c24a 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/MonitorProgressRequest.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/MonitorProgressRequest.java
@@ -1,51 +1,51 @@
-/*
- * 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.signal;
-
-import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
-import org.eclipse.net4j.util.om.trace.ContextTracer;
-
-import org.eclipse.internal.net4j.bundle.OM;
-
-/**
- * @author Eike Stepper
- */
-class MonitorProgressRequest extends Request
-{
- private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_SIGNAL, MonitorProgressRequest.class);
-
- private int correlationID;
-
- private double totalWork;
-
- private double work;
-
- public MonitorProgressRequest(SignalProtocol<?> protocol, int correlationID, double totalWork, double work)
- {
- super(protocol, SignalProtocol.SIGNAL_MONITOR_PROGRESS);
- this.correlationID = correlationID;
- this.totalWork = totalWork;
- this.work = work;
- }
-
- @Override
- protected void requesting(ExtendedDataOutputStream out) throws Exception
- {
- if (TRACER.isEnabled())
- {
- TRACER.format("Progress of signal {0}: totalWork={1}, work={2}", correlationID, totalWork, work); //$NON-NLS-1$
- }
-
- out.writeInt(correlationID);
- out.writeDouble(totalWork);
- out.writeDouble(work);
- }
-}
+/*
+ * 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.signal;
+
+import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
+import org.eclipse.net4j.util.om.trace.ContextTracer;
+
+import org.eclipse.internal.net4j.bundle.OM;
+
+/**
+ * @author Eike Stepper
+ */
+class MonitorProgressRequest extends Request
+{
+ private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_SIGNAL, MonitorProgressRequest.class);
+
+ private int correlationID;
+
+ private double totalWork;
+
+ private double work;
+
+ public MonitorProgressRequest(SignalProtocol<?> protocol, int correlationID, double totalWork, double work)
+ {
+ super(protocol, SignalProtocol.SIGNAL_MONITOR_PROGRESS);
+ this.correlationID = correlationID;
+ this.totalWork = totalWork;
+ this.work = work;
+ }
+
+ @Override
+ protected void requesting(ExtendedDataOutputStream out) throws Exception
+ {
+ if (TRACER.isEnabled())
+ {
+ TRACER.format("Progress of signal {0}: totalWork={1}, work={2}", correlationID, totalWork, work); //$NON-NLS-1$
+ }
+
+ out.writeInt(correlationID);
+ out.writeDouble(totalWork);
+ out.writeDouble(work);
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/RemoteException.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/RemoteException.java
index 1abbe2a7d1..6c805c51bf 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/RemoteException.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/RemoteException.java
@@ -1,74 +1,74 @@
-/*
- * 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.signal;
-
-/**
- * @author Eike Stepper
- * @since 2.0
- */
-public class RemoteException extends RuntimeException
-{
- private static final long serialVersionUID = 1L;
-
- private boolean whileResponding;
-
- private transient RequestWithConfirmation<?> localRequest;
-
- private StackTraceElement[] localStackTrace;
-
- /**
- * @since 4.0
- */
- public RemoteException(Throwable remoteCause, RequestWithConfirmation<?> localRequest, boolean whileResponding)
- {
- super(remoteCause);
- this.localRequest = localRequest;
- this.whileResponding = whileResponding;
- }
-
- public RemoteException(String message, boolean whileResponding)
- {
- super(message);
- this.whileResponding = whileResponding;
- }
-
- public boolean whileResponding()
- {
- return whileResponding;
- }
-
- /**
- * @since 4.0
- */
- public RequestWithConfirmation<?> getLocalRequest()
- {
- return localRequest;
- }
-
- /**
- * @since 4.0
- */
- public void setLocalStacktrace(StackTraceElement[] stackTrace)
- {
- localStackTrace = stackTrace;
- }
-
- /**
- * Returns the local stack as it stood at the time that the <i>remote</i> exception was detected <i>locally</i>. Note
- * that no local problem occurred at the point in the code identified by this stacktrace.
- *
- * @since 4.0
- */
- public StackTraceElement[] getLocalStackTrace()
- {
- return localStackTrace;
- }
-}
+/*
+ * 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.signal;
+
+/**
+ * @author Eike Stepper
+ * @since 2.0
+ */
+public class RemoteException extends RuntimeException
+{
+ private static final long serialVersionUID = 1L;
+
+ private boolean whileResponding;
+
+ private transient RequestWithConfirmation<?> localRequest;
+
+ private StackTraceElement[] localStackTrace;
+
+ /**
+ * @since 4.0
+ */
+ public RemoteException(Throwable remoteCause, RequestWithConfirmation<?> localRequest, boolean whileResponding)
+ {
+ super(remoteCause);
+ this.localRequest = localRequest;
+ this.whileResponding = whileResponding;
+ }
+
+ public RemoteException(String message, boolean whileResponding)
+ {
+ super(message);
+ this.whileResponding = whileResponding;
+ }
+
+ public boolean whileResponding()
+ {
+ return whileResponding;
+ }
+
+ /**
+ * @since 4.0
+ */
+ public RequestWithConfirmation<?> getLocalRequest()
+ {
+ return localRequest;
+ }
+
+ /**
+ * @since 4.0
+ */
+ public void setLocalStacktrace(StackTraceElement[] stackTrace)
+ {
+ localStackTrace = stackTrace;
+ }
+
+ /**
+ * Returns the local stack as it stood at the time that the <i>remote</i> exception was detected <i>locally</i>. Note
+ * that no local problem occurred at the point in the code identified by this stacktrace.
+ *
+ * @since 4.0
+ */
+ public StackTraceElement[] getLocalStackTrace()
+ {
+ return localStackTrace;
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/RemoteExceptionIndication.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/RemoteExceptionIndication.java
index a33815b9d1..bd9411fd9a 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/RemoteExceptionIndication.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/RemoteExceptionIndication.java
@@ -1,79 +1,79 @@
-/*
- * 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.signal;
-
-import org.eclipse.net4j.util.io.ExtendedDataInputStream;
-import org.eclipse.net4j.util.io.ExtendedIOUtil;
-import org.eclipse.net4j.util.om.trace.ContextTracer;
-
-import org.eclipse.internal.net4j.bundle.OM;
-
-import java.io.ByteArrayInputStream;
-import java.io.DataInputStream;
-import java.io.IOException;
-
-/**
- * @author Eike Stepper
- */
-class RemoteExceptionIndication extends Indication
-{
- private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_SIGNAL, RemoteExceptionIndication.class);
-
- private Throwable t;
-
- public RemoteExceptionIndication(SignalProtocol<?> protocol)
- {
- super(protocol, SignalProtocol.SIGNAL_REMOTE_EXCEPTION);
- }
-
- @Override
- protected void indicating(ExtendedDataInputStream in) throws Exception
- {
- int correlationID = in.readInt();
- boolean responding = in.readBoolean();
- String message = in.readString();
- if (TRACER.isEnabled())
- {
- String msg = RemoteExceptionRequest.getFirstLine(message);
- TRACER.format("Reading remote exception for signal {0}: {1}", correlationID, msg); //$NON-NLS-1$
- }
-
- try
- {
- t = deserializeThrowable(in.readByteArray());
- }
- catch (Throwable couldNotLoadExceptionClass)
- {
- // Fall through
- }
-
- if (t == null)
- {
- t = new RemoteException(message, responding);
- }
-
- getProtocol().handleRemoteException(correlationID, t, responding);
- }
-
- public static Throwable deserializeThrowable(byte[] bytes)
- {
- try
- {
- ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
- DataInputStream dis = new DataInputStream(bais);
- return (Throwable)ExtendedIOUtil.readObject(dis, OM.class.getClassLoader());
- }
- catch (IOException ex)
- {
- return null;
- }
- }
-}
+/*
+ * 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.signal;
+
+import org.eclipse.net4j.util.io.ExtendedDataInputStream;
+import org.eclipse.net4j.util.io.ExtendedIOUtil;
+import org.eclipse.net4j.util.om.trace.ContextTracer;
+
+import org.eclipse.internal.net4j.bundle.OM;
+
+import java.io.ByteArrayInputStream;
+import java.io.DataInputStream;
+import java.io.IOException;
+
+/**
+ * @author Eike Stepper
+ */
+class RemoteExceptionIndication extends Indication
+{
+ private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_SIGNAL, RemoteExceptionIndication.class);
+
+ private Throwable t;
+
+ public RemoteExceptionIndication(SignalProtocol<?> protocol)
+ {
+ super(protocol, SignalProtocol.SIGNAL_REMOTE_EXCEPTION);
+ }
+
+ @Override
+ protected void indicating(ExtendedDataInputStream in) throws Exception
+ {
+ int correlationID = in.readInt();
+ boolean responding = in.readBoolean();
+ String message = in.readString();
+ if (TRACER.isEnabled())
+ {
+ String msg = RemoteExceptionRequest.getFirstLine(message);
+ TRACER.format("Reading remote exception for signal {0}: {1}", correlationID, msg); //$NON-NLS-1$
+ }
+
+ try
+ {
+ t = deserializeThrowable(in.readByteArray());
+ }
+ catch (Throwable couldNotLoadExceptionClass)
+ {
+ // Fall through
+ }
+
+ if (t == null)
+ {
+ t = new RemoteException(message, responding);
+ }
+
+ getProtocol().handleRemoteException(correlationID, t, responding);
+ }
+
+ public static Throwable deserializeThrowable(byte[] bytes)
+ {
+ try
+ {
+ ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
+ DataInputStream dis = new DataInputStream(bais);
+ return (Throwable)ExtendedIOUtil.readObject(dis, OM.class.getClassLoader());
+ }
+ catch (IOException ex)
+ {
+ return null;
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/RemoteExceptionRequest.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/RemoteExceptionRequest.java
index 2a74fa22ef..bd20af662c 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/RemoteExceptionRequest.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/RemoteExceptionRequest.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.signal;
-
-import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
-import org.eclipse.net4j.util.io.ExtendedIOUtil;
-import org.eclipse.net4j.util.om.trace.ContextTracer;
-
-import org.eclipse.internal.net4j.bundle.OM;
-
-import java.io.ByteArrayOutputStream;
-import java.io.DataOutputStream;
-
-/**
- * @author Eike Stepper
- */
-class RemoteExceptionRequest extends Request
-{
- private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_SIGNAL, RemoteExceptionRequest.class);
-
- private int correlationID;
-
- private boolean responding;
-
- private String message;
-
- private Throwable t;
-
- public RemoteExceptionRequest(SignalProtocol<?> protocol, int correlationID, boolean responding, String message,
- Throwable t)
- {
- super(protocol, SignalProtocol.SIGNAL_REMOTE_EXCEPTION);
- this.correlationID = correlationID;
- this.message = message;
- this.t = t;
- this.responding = responding;
- }
-
- @Override
- protected void requesting(ExtendedDataOutputStream out) throws Exception
- {
- if (TRACER.isEnabled())
- {
- String msg = getFirstLine(message);
- TRACER.format("Writing remote exception for signal {0}: {1}", correlationID, msg); //$NON-NLS-1$
- }
-
- out.writeInt(correlationID);
- out.writeBoolean(responding);
- out.writeString(message);
- out.writeByteArray(serializeThrowable(t));
- }
-
- public static byte[] serializeThrowable(Throwable t)
- {
- try
- {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- DataOutputStream dos = new DataOutputStream(baos);
- ExtendedIOUtil.writeObject(dos, t);
- return baos.toByteArray();
- }
- catch (Exception ex)
- {
- return null;
- }
- }
-
- public static String getFirstLine(String message)
- {
- if (message == null)
- {
- return null;
- }
-
- int nl = message.indexOf('\n');
- if (nl == -1)
- {
- nl = message.length();
- }
-
- if (nl > 100)
- {
- nl = 100;
- }
-
- return message.substring(0, nl);
- }
-}
+/*
+ * 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.signal;
+
+import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
+import org.eclipse.net4j.util.io.ExtendedIOUtil;
+import org.eclipse.net4j.util.om.trace.ContextTracer;
+
+import org.eclipse.internal.net4j.bundle.OM;
+
+import java.io.ByteArrayOutputStream;
+import java.io.DataOutputStream;
+
+/**
+ * @author Eike Stepper
+ */
+class RemoteExceptionRequest extends Request
+{
+ private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_SIGNAL, RemoteExceptionRequest.class);
+
+ private int correlationID;
+
+ private boolean responding;
+
+ private String message;
+
+ private Throwable t;
+
+ public RemoteExceptionRequest(SignalProtocol<?> protocol, int correlationID, boolean responding, String message,
+ Throwable t)
+ {
+ super(protocol, SignalProtocol.SIGNAL_REMOTE_EXCEPTION);
+ this.correlationID = correlationID;
+ this.message = message;
+ this.t = t;
+ this.responding = responding;
+ }
+
+ @Override
+ protected void requesting(ExtendedDataOutputStream out) throws Exception
+ {
+ if (TRACER.isEnabled())
+ {
+ String msg = getFirstLine(message);
+ TRACER.format("Writing remote exception for signal {0}: {1}", correlationID, msg); //$NON-NLS-1$
+ }
+
+ out.writeInt(correlationID);
+ out.writeBoolean(responding);
+ out.writeString(message);
+ out.writeByteArray(serializeThrowable(t));
+ }
+
+ public static byte[] serializeThrowable(Throwable t)
+ {
+ try
+ {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ DataOutputStream dos = new DataOutputStream(baos);
+ ExtendedIOUtil.writeObject(dos, t);
+ return baos.toByteArray();
+ }
+ catch (Exception ex)
+ {
+ return null;
+ }
+ }
+
+ public static String getFirstLine(String message)
+ {
+ if (message == null)
+ {
+ return null;
+ }
+
+ int nl = message.indexOf('\n');
+ if (nl == -1)
+ {
+ nl = message.length();
+ }
+
+ if (nl > 100)
+ {
+ nl = 100;
+ }
+
+ return message.substring(0, nl);
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/Request.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/Request.java
index bac412b30e..d933142d48 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/Request.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/Request.java
@@ -1,67 +1,67 @@
-/*
- * 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.signal;
-
-import org.eclipse.net4j.buffer.BufferInputStream;
-import org.eclipse.net4j.buffer.BufferOutputStream;
-import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
-
-/**
- * @author Eike Stepper
- */
-public abstract class Request extends SignalActor
-{
- /**
- * @since 2.0
- */
- public Request(SignalProtocol<?> protocol, short id, String name)
- {
- super(protocol, id, name);
- }
-
- /**
- * @since 2.0
- */
- public Request(SignalProtocol<?> protocol, short signalID)
- {
- super(protocol, signalID);
- }
-
- /**
- * @since 2.0
- */
- public Request(SignalProtocol<?> protocol, Enum<?> literal)
- {
- super(protocol, literal);
- }
-
- /**
- * @since 2.0
- */
- public void sendAsync() throws Exception
- {
- getProtocol().startSignal(this, getProtocol().getTimeout());
- }
-
- @Override
- void doExecute(BufferInputStream in, BufferOutputStream out) throws Exception
- {
- doOutput(out);
- }
-
- protected abstract void requesting(ExtendedDataOutputStream out) throws Exception;
-
- @Override
- void doExtendedOutput(ExtendedDataOutputStream out) throws Exception
- {
- requesting(out);
- }
-}
+/*
+ * 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.signal;
+
+import org.eclipse.net4j.buffer.BufferInputStream;
+import org.eclipse.net4j.buffer.BufferOutputStream;
+import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
+
+/**
+ * @author Eike Stepper
+ */
+public abstract class Request extends SignalActor
+{
+ /**
+ * @since 2.0
+ */
+ public Request(SignalProtocol<?> protocol, short id, String name)
+ {
+ super(protocol, id, name);
+ }
+
+ /**
+ * @since 2.0
+ */
+ public Request(SignalProtocol<?> protocol, short signalID)
+ {
+ super(protocol, signalID);
+ }
+
+ /**
+ * @since 2.0
+ */
+ public Request(SignalProtocol<?> protocol, Enum<?> literal)
+ {
+ super(protocol, literal);
+ }
+
+ /**
+ * @since 2.0
+ */
+ public void sendAsync() throws Exception
+ {
+ getProtocol().startSignal(this, getProtocol().getTimeout());
+ }
+
+ @Override
+ void doExecute(BufferInputStream in, BufferOutputStream out) throws Exception
+ {
+ doOutput(out);
+ }
+
+ protected abstract void requesting(ExtendedDataOutputStream out) throws Exception;
+
+ @Override
+ void doExtendedOutput(ExtendedDataOutputStream out) throws Exception
+ {
+ requesting(out);
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/RequestWithConfirmation.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/RequestWithConfirmation.java
index 84555197a5..062caed720 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/RequestWithConfirmation.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/RequestWithConfirmation.java
@@ -1,141 +1,141 @@
-/*
- * 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.signal;
-
-import org.eclipse.net4j.buffer.BufferInputStream;
-import org.eclipse.net4j.buffer.BufferOutputStream;
-import org.eclipse.net4j.util.io.ExtendedDataInputStream;
-import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
-
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Future;
-
-/**
- * @author Eike Stepper
- */
-public abstract class RequestWithConfirmation<RESULT> extends SignalActor
-{
- private RESULT result;
-
- /**
- * @since 2.0
- */
- public RequestWithConfirmation(SignalProtocol<?> protocol, short id, String name)
- {
- super(protocol, id, name);
- }
-
- /**
- * @since 2.0
- */
- public RequestWithConfirmation(SignalProtocol<?> protocol, short signalID)
- {
- super(protocol, signalID);
- }
-
- /**
- * @since 2.0
- */
- public RequestWithConfirmation(SignalProtocol<?> protocol, Enum<?> literal)
- {
- super(protocol, literal);
- }
-
- /**
- * @since 2.0
- */
- public Future<RESULT> sendAsync()
- {
- ExecutorService executorService = getAsyncExecutorService();
- return executorService.submit(new Callable<RESULT>()
- {
- public RESULT call() throws Exception
- {
- return doSend(getProtocol().getTimeout());
- }
- });
- }
-
- /**
- * @since 2.0
- */
- public RESULT send() throws Exception, RemoteException
- {
- return doSend(getProtocol().getTimeout());
- }
-
- /**
- * @since 2.0
- */
- public RESULT send(long timeout) throws Exception, RemoteException
- {
- return doSend(timeout);
- }
-
- RESULT doSend(long timeout) throws Exception
- {
- result = null;
- getProtocol().startSignal(this, timeout);
- return result;
- }
-
- /**
- * @since 2.0
- */
- protected ExecutorService getAsyncExecutorService()
- {
- return getProtocol().getExecutorService();
- }
-
- @Override
- void doExecute(BufferInputStream in, BufferOutputStream out) throws Exception
- {
- doOutput(out);
- doInput(in);
- }
-
- protected abstract void requesting(ExtendedDataOutputStream out) throws Exception;
-
- /**
- * <b>Important Note:</b> The confirmation must not be empty, i.e. the stream must be used at least to read a
- * <code>boolean</code>. Otherwise synchronization problems will result!
- */
- protected abstract RESULT confirming(ExtendedDataInputStream in) throws Exception;
-
- @Override
- void doExtendedOutput(ExtendedDataOutputStream out) throws Exception
- {
- requesting(out);
- }
-
- @Override
- void doExtendedInput(ExtendedDataInputStream in) throws Exception
- {
- result = confirming(in);
- }
-
- void setRemoteException(Throwable t, boolean responding)
- {
- RemoteException remoteException = getRemoteException(t, responding);
- getBufferInputStream().setException(remoteException);
- }
-
- private RemoteException getRemoteException(Throwable t, boolean responding)
- {
- if (t instanceof RemoteException)
- {
- return (RemoteException)t;
- }
-
- return new RemoteException(t, this, responding);
- }
-}
+/*
+ * 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.signal;
+
+import org.eclipse.net4j.buffer.BufferInputStream;
+import org.eclipse.net4j.buffer.BufferOutputStream;
+import org.eclipse.net4j.util.io.ExtendedDataInputStream;
+import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
+
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Future;
+
+/**
+ * @author Eike Stepper
+ */
+public abstract class RequestWithConfirmation<RESULT> extends SignalActor
+{
+ private RESULT result;
+
+ /**
+ * @since 2.0
+ */
+ public RequestWithConfirmation(SignalProtocol<?> protocol, short id, String name)
+ {
+ super(protocol, id, name);
+ }
+
+ /**
+ * @since 2.0
+ */
+ public RequestWithConfirmation(SignalProtocol<?> protocol, short signalID)
+ {
+ super(protocol, signalID);
+ }
+
+ /**
+ * @since 2.0
+ */
+ public RequestWithConfirmation(SignalProtocol<?> protocol, Enum<?> literal)
+ {
+ super(protocol, literal);
+ }
+
+ /**
+ * @since 2.0
+ */
+ public Future<RESULT> sendAsync()
+ {
+ ExecutorService executorService = getAsyncExecutorService();
+ return executorService.submit(new Callable<RESULT>()
+ {
+ public RESULT call() throws Exception
+ {
+ return doSend(getProtocol().getTimeout());
+ }
+ });
+ }
+
+ /**
+ * @since 2.0
+ */
+ public RESULT send() throws Exception, RemoteException
+ {
+ return doSend(getProtocol().getTimeout());
+ }
+
+ /**
+ * @since 2.0
+ */
+ public RESULT send(long timeout) throws Exception, RemoteException
+ {
+ return doSend(timeout);
+ }
+
+ RESULT doSend(long timeout) throws Exception
+ {
+ result = null;
+ getProtocol().startSignal(this, timeout);
+ return result;
+ }
+
+ /**
+ * @since 2.0
+ */
+ protected ExecutorService getAsyncExecutorService()
+ {
+ return getProtocol().getExecutorService();
+ }
+
+ @Override
+ void doExecute(BufferInputStream in, BufferOutputStream out) throws Exception
+ {
+ doOutput(out);
+ doInput(in);
+ }
+
+ protected abstract void requesting(ExtendedDataOutputStream out) throws Exception;
+
+ /**
+ * <b>Important Note:</b> The confirmation must not be empty, i.e. the stream must be used at least to read a
+ * <code>boolean</code>. Otherwise synchronization problems will result!
+ */
+ protected abstract RESULT confirming(ExtendedDataInputStream in) throws Exception;
+
+ @Override
+ void doExtendedOutput(ExtendedDataOutputStream out) throws Exception
+ {
+ requesting(out);
+ }
+
+ @Override
+ void doExtendedInput(ExtendedDataInputStream in) throws Exception
+ {
+ result = confirming(in);
+ }
+
+ void setRemoteException(Throwable t, boolean responding)
+ {
+ RemoteException remoteException = getRemoteException(t, responding);
+ getBufferInputStream().setException(remoteException);
+ }
+
+ private RemoteException getRemoteException(Throwable t, boolean responding)
+ {
+ if (t instanceof RemoteException)
+ {
+ return (RemoteException)t;
+ }
+
+ return new RemoteException(t, this, responding);
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/RequestWithMonitoring.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/RequestWithMonitoring.java
index 902860a2aa..ebcdd509e0 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/RequestWithMonitoring.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/RequestWithMonitoring.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.signal;
-
-import org.eclipse.net4j.buffer.BufferInputStream;
-import org.eclipse.net4j.buffer.BufferOutputStream;
-import org.eclipse.net4j.util.ImplementationError;
-import org.eclipse.net4j.util.concurrent.ConcurrencyUtil;
-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.internal.net4j.bundle.OM;
-
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Future;
-
-/**
- * @author Eike Stepper
- * @since 2.0
- */
-public abstract class RequestWithMonitoring<RESULT> extends RequestWithConfirmation<RESULT>
-{
- /**
- * @since 2.0
- */
- public static final long DEFAULT_CANCELATION_POLL_INTERVAL = 100;
-
- /**
- * @since 2.0
- */
- public static final int DEFAULT_MONITOR_PROGRESS_SECONDS = 1;
-
- /**
- * @since 2.0
- */
- public static final int DEFAULT_MONITOR_TIMEOUT_SECONDS = 10;
-
- private OMMonitor mainMonitor;
-
- private OMMonitor remoteMonitor;
-
- private Object monitorLock = new Object();
-
- /**
- * @since 2.0
- */
- public RequestWithMonitoring(SignalProtocol<?> protocol, short id, String name)
- {
- super(protocol, id, name);
- }
-
- /**
- * @since 2.0
- */
- public RequestWithMonitoring(SignalProtocol<?> protocol, short signalID)
- {
- super(protocol, signalID);
- }
-
- /**
- * @since 2.0
- */
- public RequestWithMonitoring(SignalProtocol<?> protocol, Enum<?> literal)
- {
- super(protocol, literal);
- }
-
- @Override
- public Future<RESULT> sendAsync()
- {
- initMainMonitor(null);
- return super.sendAsync();
- }
-
- public Future<RESULT> sendAsync(OMMonitor monitor)
- {
- initMainMonitor(monitor);
- return super.sendAsync();
- }
-
- @Override
- public RESULT send() throws Exception, RemoteException
- {
- initMainMonitor(null);
- return super.send();
- }
-
- @Override
- public RESULT send(long timeout) throws Exception, RemoteException
- {
- initMainMonitor(null);
- return super.send(timeout);
- }
-
- public RESULT send(OMMonitor monitor) throws Exception, RemoteException
- {
- initMainMonitor(monitor);
- return super.send();
- }
-
- public RESULT send(long timeout, OMMonitor monitor) throws Exception, RemoteException
- {
- initMainMonitor(monitor);
- return super.send(timeout);
- }
-
- @Override
- protected final void requesting(ExtendedDataOutputStream out) throws Exception
- {
- double remoteWork = OMMonitor.HUNDRED - getRequestingWorkPercent() - getConfirmingWorkPercent();
- if (remoteWork < OMMonitor.ZERO)
- {
- throw new ImplementationError("Remote work must not be negative: " + remoteWork); //$NON-NLS-1$
- }
-
- mainMonitor.begin(OMMonitor.HUNDRED);
- OMMonitor subMonitor = mainMonitor.fork(remoteWork);
- synchronized (monitorLock)
- {
- remoteMonitor = subMonitor;
- }
-
- ExecutorService executorService = getCancelationExecutorService();
- if (executorService != null)
- {
- executorService.execute(new Runnable()
- {
- public void run()
- {
- while (mainMonitor != null)
- {
- ConcurrencyUtil.sleep(getCancelationPollInterval());
- if (mainMonitor != null && mainMonitor.isCanceled())
- {
- try
- {
- new MonitorCanceledRequest(getProtocol(), getCorrelationID()).sendAsync();
- }
- catch (Exception ex)
- {
- OM.LOG.error(ex);
- }
-
- return;
- }
- }
- }
- });
- }
-
- out.writeInt(getMonitorProgressSeconds());
- out.writeInt(getMonitorTimeoutSeconds());
- requesting(out, mainMonitor.fork(getRequestingWorkPercent()));
- }
-
- @Override
- protected final RESULT confirming(ExtendedDataInputStream in) throws Exception
- {
- return confirming(in, mainMonitor.fork(getConfirmingWorkPercent()));
- }
-
- protected abstract void requesting(ExtendedDataOutputStream out, OMMonitor monitor) throws Exception;
-
- /**
- * <b>Important Note:</b> The confirmation must not be empty, i.e. the stream must be used at least to read a
- * <code>boolean</code>. Otherwise synchronization problems will result!
- */
- protected abstract RESULT confirming(ExtendedDataInputStream in, OMMonitor monitor) throws Exception;
-
- /**
- * @since 2.0
- */
- protected ExecutorService getCancelationExecutorService()
- {
- return getProtocol().getExecutorService();
- }
-
- /**
- * @since 2.0
- */
- protected long getCancelationPollInterval()
- {
- return DEFAULT_CANCELATION_POLL_INTERVAL;
- }
-
- /**
- * @since 2.0
- */
- protected int getMonitorProgressSeconds()
- {
- return DEFAULT_MONITOR_PROGRESS_SECONDS;
- }
-
- /**
- * @since 2.0
- */
- protected int getMonitorTimeoutSeconds()
- {
- return DEFAULT_MONITOR_TIMEOUT_SECONDS;
- }
-
- /**
- * @since 2.0
- */
- protected int getRequestingWorkPercent()
- {
- return 2;
- }
-
- /**
- * @since 2.0
- */
- protected int getConfirmingWorkPercent()
- {
- return 1;
- }
-
- @Override
- void doExecute(BufferInputStream in, BufferOutputStream out) throws Exception
- {
- try
- {
- super.doExecute(in, out);
- }
- finally
- {
- synchronized (monitorLock)
- {
- try
- {
- if (remoteMonitor != null)
- {
- remoteMonitor.done();
- }
- }
- catch (Exception ex)
- {
- OM.LOG.error(ex);
- }
- finally
- {
- remoteMonitor = null;
- }
- }
-
- try
- {
- if (mainMonitor != null)
- {
- mainMonitor.done();
- }
- }
- finally
- {
- mainMonitor = null;
- }
- }
- }
-
- void setMonitorProgress(double totalWork, double work)
- {
- getBufferInputStream().restartTimeout();
- synchronized (monitorLock)
- {
- if (remoteMonitor != null)
- {
- if (!remoteMonitor.hasBegun())
- {
- remoteMonitor.begin(totalWork);
- remoteMonitor.worked(work);
- }
- else
- {
- double oldRatio = remoteMonitor.getWork() / remoteMonitor.getTotalWork();
- double newRatio = work / totalWork;
-
- double newWork = newRatio - oldRatio;
- newWork *= remoteMonitor.getTotalWork();
- if (newWork >= OMMonitor.ZERO)
- {
- remoteMonitor.worked(newWork);
- }
- }
- }
- }
- }
-
- private void initMainMonitor(OMMonitor monitor)
- {
- mainMonitor = monitor == null ? new Monitor() : monitor;
- }
-}
+/*
+ * 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.signal;
+
+import org.eclipse.net4j.buffer.BufferInputStream;
+import org.eclipse.net4j.buffer.BufferOutputStream;
+import org.eclipse.net4j.util.ImplementationError;
+import org.eclipse.net4j.util.concurrent.ConcurrencyUtil;
+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.internal.net4j.bundle.OM;
+
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Future;
+
+/**
+ * @author Eike Stepper
+ * @since 2.0
+ */
+public abstract class RequestWithMonitoring<RESULT> extends RequestWithConfirmation<RESULT>
+{
+ /**
+ * @since 2.0
+ */
+ public static final long DEFAULT_CANCELATION_POLL_INTERVAL = 100;
+
+ /**
+ * @since 2.0
+ */
+ public static final int DEFAULT_MONITOR_PROGRESS_SECONDS = 1;
+
+ /**
+ * @since 2.0
+ */
+ public static final int DEFAULT_MONITOR_TIMEOUT_SECONDS = 10;
+
+ private OMMonitor mainMonitor;
+
+ private OMMonitor remoteMonitor;
+
+ private Object monitorLock = new Object();
+
+ /**
+ * @since 2.0
+ */
+ public RequestWithMonitoring(SignalProtocol<?> protocol, short id, String name)
+ {
+ super(protocol, id, name);
+ }
+
+ /**
+ * @since 2.0
+ */
+ public RequestWithMonitoring(SignalProtocol<?> protocol, short signalID)
+ {
+ super(protocol, signalID);
+ }
+
+ /**
+ * @since 2.0
+ */
+ public RequestWithMonitoring(SignalProtocol<?> protocol, Enum<?> literal)
+ {
+ super(protocol, literal);
+ }
+
+ @Override
+ public Future<RESULT> sendAsync()
+ {
+ initMainMonitor(null);
+ return super.sendAsync();
+ }
+
+ public Future<RESULT> sendAsync(OMMonitor monitor)
+ {
+ initMainMonitor(monitor);
+ return super.sendAsync();
+ }
+
+ @Override
+ public RESULT send() throws Exception, RemoteException
+ {
+ initMainMonitor(null);
+ return super.send();
+ }
+
+ @Override
+ public RESULT send(long timeout) throws Exception, RemoteException
+ {
+ initMainMonitor(null);
+ return super.send(timeout);
+ }
+
+ public RESULT send(OMMonitor monitor) throws Exception, RemoteException
+ {
+ initMainMonitor(monitor);
+ return super.send();
+ }
+
+ public RESULT send(long timeout, OMMonitor monitor) throws Exception, RemoteException
+ {
+ initMainMonitor(monitor);
+ return super.send(timeout);
+ }
+
+ @Override
+ protected final void requesting(ExtendedDataOutputStream out) throws Exception
+ {
+ double remoteWork = OMMonitor.HUNDRED - getRequestingWorkPercent() - getConfirmingWorkPercent();
+ if (remoteWork < OMMonitor.ZERO)
+ {
+ throw new ImplementationError("Remote work must not be negative: " + remoteWork); //$NON-NLS-1$
+ }
+
+ mainMonitor.begin(OMMonitor.HUNDRED);
+ OMMonitor subMonitor = mainMonitor.fork(remoteWork);
+ synchronized (monitorLock)
+ {
+ remoteMonitor = subMonitor;
+ }
+
+ ExecutorService executorService = getCancelationExecutorService();
+ if (executorService != null)
+ {
+ executorService.execute(new Runnable()
+ {
+ public void run()
+ {
+ while (mainMonitor != null)
+ {
+ ConcurrencyUtil.sleep(getCancelationPollInterval());
+ if (mainMonitor != null && mainMonitor.isCanceled())
+ {
+ try
+ {
+ new MonitorCanceledRequest(getProtocol(), getCorrelationID()).sendAsync();
+ }
+ catch (Exception ex)
+ {
+ OM.LOG.error(ex);
+ }
+
+ return;
+ }
+ }
+ }
+ });
+ }
+
+ out.writeInt(getMonitorProgressSeconds());
+ out.writeInt(getMonitorTimeoutSeconds());
+ requesting(out, mainMonitor.fork(getRequestingWorkPercent()));
+ }
+
+ @Override
+ protected final RESULT confirming(ExtendedDataInputStream in) throws Exception
+ {
+ return confirming(in, mainMonitor.fork(getConfirmingWorkPercent()));
+ }
+
+ protected abstract void requesting(ExtendedDataOutputStream out, OMMonitor monitor) throws Exception;
+
+ /**
+ * <b>Important Note:</b> The confirmation must not be empty, i.e. the stream must be used at least to read a
+ * <code>boolean</code>. Otherwise synchronization problems will result!
+ */
+ protected abstract RESULT confirming(ExtendedDataInputStream in, OMMonitor monitor) throws Exception;
+
+ /**
+ * @since 2.0
+ */
+ protected ExecutorService getCancelationExecutorService()
+ {
+ return getProtocol().getExecutorService();
+ }
+
+ /**
+ * @since 2.0
+ */
+ protected long getCancelationPollInterval()
+ {
+ return DEFAULT_CANCELATION_POLL_INTERVAL;
+ }
+
+ /**
+ * @since 2.0
+ */
+ protected int getMonitorProgressSeconds()
+ {
+ return DEFAULT_MONITOR_PROGRESS_SECONDS;
+ }
+
+ /**
+ * @since 2.0
+ */
+ protected int getMonitorTimeoutSeconds()
+ {
+ return DEFAULT_MONITOR_TIMEOUT_SECONDS;
+ }
+
+ /**
+ * @since 2.0
+ */
+ protected int getRequestingWorkPercent()
+ {
+ return 2;
+ }
+
+ /**
+ * @since 2.0
+ */
+ protected int getConfirmingWorkPercent()
+ {
+ return 1;
+ }
+
+ @Override
+ void doExecute(BufferInputStream in, BufferOutputStream out) throws Exception
+ {
+ try
+ {
+ super.doExecute(in, out);
+ }
+ finally
+ {
+ synchronized (monitorLock)
+ {
+ try
+ {
+ if (remoteMonitor != null)
+ {
+ remoteMonitor.done();
+ }
+ }
+ catch (Exception ex)
+ {
+ OM.LOG.error(ex);
+ }
+ finally
+ {
+ remoteMonitor = null;
+ }
+ }
+
+ try
+ {
+ if (mainMonitor != null)
+ {
+ mainMonitor.done();
+ }
+ }
+ finally
+ {
+ mainMonitor = null;
+ }
+ }
+ }
+
+ void setMonitorProgress(double totalWork, double work)
+ {
+ getBufferInputStream().restartTimeout();
+ synchronized (monitorLock)
+ {
+ if (remoteMonitor != null)
+ {
+ if (!remoteMonitor.hasBegun())
+ {
+ remoteMonitor.begin(totalWork);
+ remoteMonitor.worked(work);
+ }
+ else
+ {
+ double oldRatio = remoteMonitor.getWork() / remoteMonitor.getTotalWork();
+ double newRatio = work / totalWork;
+
+ double newWork = newRatio - oldRatio;
+ newWork *= remoteMonitor.getTotalWork();
+ if (newWork >= OMMonitor.ZERO)
+ {
+ remoteMonitor.worked(newWork);
+ }
+ }
+ }
+ }
+ }
+
+ private void initMainMonitor(OMMonitor monitor)
+ {
+ mainMonitor = monitor == null ? new Monitor() : monitor;
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/SetTimeoutIndication.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/SetTimeoutIndication.java
index 30cf1f6f89..e85603d896 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/SetTimeoutIndication.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/SetTimeoutIndication.java
@@ -1,48 +1,48 @@
-/*
- * 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.signal;
-
-import org.eclipse.net4j.util.io.ExtendedDataInputStream;
-import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
-import org.eclipse.net4j.util.om.trace.ContextTracer;
-
-import org.eclipse.internal.net4j.bundle.OM;
-
-/**
- * @author Eike Stepper
- */
-class SetTimeoutIndication extends IndicationWithResponse
-{
- private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_SIGNAL, SetTimeoutIndication.class);
-
- public SetTimeoutIndication(SignalProtocol<?> protocol)
- {
- super(protocol, SignalProtocol.SIGNAL_SET_TIMEOUT);
- }
-
- @Override
- protected void indicating(ExtendedDataInputStream in) throws Exception
- {
- long timeout = in.readLong();
- if (TRACER.isEnabled())
- {
- TRACER.format("Set timeout: {0}", timeout); //$NON-NLS-1$
- }
-
- getProtocol().handleSetTimeOut(timeout);
- }
-
- @Override
- protected void responding(ExtendedDataOutputStream out) throws Exception
- {
- 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.signal;
+
+import org.eclipse.net4j.util.io.ExtendedDataInputStream;
+import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
+import org.eclipse.net4j.util.om.trace.ContextTracer;
+
+import org.eclipse.internal.net4j.bundle.OM;
+
+/**
+ * @author Eike Stepper
+ */
+class SetTimeoutIndication extends IndicationWithResponse
+{
+ private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_SIGNAL, SetTimeoutIndication.class);
+
+ public SetTimeoutIndication(SignalProtocol<?> protocol)
+ {
+ super(protocol, SignalProtocol.SIGNAL_SET_TIMEOUT);
+ }
+
+ @Override
+ protected void indicating(ExtendedDataInputStream in) throws Exception
+ {
+ long timeout = in.readLong();
+ if (TRACER.isEnabled())
+ {
+ TRACER.format("Set timeout: {0}", timeout); //$NON-NLS-1$
+ }
+
+ getProtocol().handleSetTimeOut(timeout);
+ }
+
+ @Override
+ protected void responding(ExtendedDataOutputStream out) throws Exception
+ {
+ out.writeBoolean(true);
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/SetTimeoutRequest.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/SetTimeoutRequest.java
index cc058d3d86..8b9c3ecf74 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/SetTimeoutRequest.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/SetTimeoutRequest.java
@@ -1,50 +1,50 @@
-/*
- * 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.signal;
-
-import org.eclipse.net4j.util.io.ExtendedDataInputStream;
-import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
-import org.eclipse.net4j.util.om.trace.ContextTracer;
-
-import org.eclipse.internal.net4j.bundle.OM;
-
-/**
- * @author Eike Stepper
- */
-class SetTimeoutRequest extends RequestWithConfirmation<Boolean>
-{
- private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_SIGNAL, SetTimeoutRequest.class);
-
- private long timeout;
-
- public SetTimeoutRequest(SignalProtocol<?> protocol, long timeout)
- {
- super(protocol, SignalProtocol.SIGNAL_SET_TIMEOUT);
- this.timeout = timeout;
- }
-
- @Override
- protected void requesting(ExtendedDataOutputStream out) throws Exception
- {
- if (TRACER.isEnabled())
- {
- TRACER.format("Set timeout: {0}", timeout); //$NON-NLS-1$
- }
-
- out.writeLong(timeout);
- }
-
- @Override
- protected Boolean confirming(ExtendedDataInputStream in) throws Exception
- {
- 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.signal;
+
+import org.eclipse.net4j.util.io.ExtendedDataInputStream;
+import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
+import org.eclipse.net4j.util.om.trace.ContextTracer;
+
+import org.eclipse.internal.net4j.bundle.OM;
+
+/**
+ * @author Eike Stepper
+ */
+class SetTimeoutRequest extends RequestWithConfirmation<Boolean>
+{
+ private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_SIGNAL, SetTimeoutRequest.class);
+
+ private long timeout;
+
+ public SetTimeoutRequest(SignalProtocol<?> protocol, long timeout)
+ {
+ super(protocol, SignalProtocol.SIGNAL_SET_TIMEOUT);
+ this.timeout = timeout;
+ }
+
+ @Override
+ protected void requesting(ExtendedDataOutputStream out) throws Exception
+ {
+ if (TRACER.isEnabled())
+ {
+ TRACER.format("Set timeout: {0}", timeout); //$NON-NLS-1$
+ }
+
+ out.writeLong(timeout);
+ }
+
+ @Override
+ protected Boolean confirming(ExtendedDataInputStream in) throws Exception
+ {
+ return in.readBoolean();
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/Signal.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/Signal.java
index 8f5c87a090..03ebd2b755 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/Signal.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/Signal.java
@@ -1,353 +1,353 @@
-/*
- * 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.signal;
-
-import org.eclipse.net4j.buffer.BufferInputStream;
-import org.eclipse.net4j.buffer.BufferOutputStream;
-import org.eclipse.net4j.util.ReflectUtil;
-import org.eclipse.net4j.util.io.ExtendedDataInputStream;
-import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
-import org.eclipse.net4j.util.io.IOTimeoutException;
-import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
-import org.eclipse.net4j.util.om.trace.ContextTracer;
-
-import org.eclipse.internal.net4j.bundle.OM;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.text.MessageFormat;
-
-/**
- * @author Eike Stepper
- */
-public abstract class Signal implements Runnable
-{
- /**
- * @since 2.0
- */
- public static final long NO_TIMEOUT = BufferInputStream.NO_TIMEOUT;
-
- private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_SIGNAL, Signal.class);
-
- private SignalProtocol<?> protocol;
-
- private short id;
-
- private String name;
-
- private int correlationID;
-
- private BufferInputStream bufferInputStream;
-
- private BufferOutputStream bufferOutputStream;
-
- private Object currentStream;
-
- /**
- * Both implementation classes of a logical signal must have the same signalID. The signalID of a user signals must be
- * equal to or greater than zero.
- *
- * @since 2.0
- */
- public Signal(SignalProtocol<?> protocol, short id, String name)
- {
- this.protocol = protocol;
- this.id = id;
- this.name = name;
- }
-
- /**
- * @since 2.0
- * @see #Signal(SignalProtocol, short, String)
- */
- public Signal(SignalProtocol<?> protocol, short id)
- {
- this(protocol, id, null);
- }
-
- /**
- * @since 2.0
- * @see #Signal(SignalProtocol, short, String)
- */
- public Signal(SignalProtocol<?> protocol, Enum<?> literal)
- {
- this(protocol, (short)literal.ordinal(), literal.name());
- }
-
- public SignalProtocol<?> getProtocol()
- {
- LifecycleUtil.checkActive(protocol);
- return protocol;
- }
-
- /**
- * Returns the short integer ID of this signal that is unique among all signals of the associated
- * {@link #getProtocol() protocol}.
- *
- * @since 2.0
- */
- public final short getID()
- {
- return id;
- }
-
- /**
- * @since 2.0
- */
- public String getName()
- {
- if (name == null)
- {
- // Needs no synchronization because any thread would set the same value.
- name = ReflectUtil.getSimpleClassName(this);
- }
-
- return name;
- }
-
- /**
- * @since 2.0
- */
- public final int getCorrelationID()
- {
- return correlationID;
- }
-
- /**
- * @since 2.0
- */
- @Override
- public String toString()
- {
- return MessageFormat.format("Signal[protocol={0}, id={1}, name={2}, correlation={3}]", getProtocol().getType(), //$NON-NLS-1$
- getID(), getName(), getCorrelationID());
- }
-
- public final void run()
- {
- String threadName = null;
-
- try
- {
- if (OM.SET_SIGNAL_THREAD_NAME)
- {
- threadName = getClass().getSimpleName();
- Thread.currentThread().setName(threadName);
- }
-
- runSync();
- }
- catch (Exception ex)
- {
- if (getProtocol().isActive())
- {
- OM.LOG.error(ex);
- }
- else
- {
- if (TRACER.isEnabled())
- {
- TRACER.trace("Exception while protocol is inactive", ex); //$NON-NLS-1$
- }
- }
- }
- finally
- {
- if (threadName != null)
- {
- Thread.currentThread().setName(threadName + "(FINISHED)"); //$NON-NLS-1$
- }
- }
- }
-
- protected final BufferInputStream getBufferInputStream()
- {
- return bufferInputStream;
- }
-
- protected final BufferOutputStream getBufferOutputStream()
- {
- return bufferOutputStream;
- }
-
- /**
- * @since 2.0
- */
- protected final void flush() throws IOException
- {
- if (currentStream instanceof OutputStream)
- {
- ((OutputStream)currentStream).flush();
- }
- }
-
- /**
- * @since 2.0
- */
- protected InputStream getCurrentInputStream()
- {
- if (currentStream instanceof InputStream)
- {
- return (InputStream)currentStream;
- }
-
- return null;
- }
-
- /**
- * @since 2.0
- */
- protected OutputStream getCurrentOutputStream()
- {
- if (currentStream instanceof OutputStream)
- {
- return (OutputStream)currentStream;
- }
-
- return null;
- }
-
- protected InputStream wrapInputStream(InputStream in) throws IOException
- {
- currentStream = getProtocol().wrapInputStream(in);
- return (InputStream)currentStream;
- }
-
- protected OutputStream wrapOutputStream(OutputStream out) throws IOException
- {
- currentStream = getProtocol().wrapOutputStream(out);
- return (OutputStream)currentStream;
- }
-
- protected void finishInputStream(InputStream in) throws IOException
- {
- currentStream = null;
- getProtocol().finishInputStream(in);
- }
-
- protected void finishOutputStream(OutputStream out) throws IOException
- {
- currentStream = null;
- getProtocol().finishOutputStream(out);
- }
-
- protected abstract void execute(BufferInputStream in, BufferOutputStream out) throws Exception;
-
- void runSync() throws Exception
- {
- Exception exception = null;
-
- try
- {
- execute(bufferInputStream, bufferOutputStream);
- }
- catch (IOTimeoutException ex) // Thrown from BufferInputStream
- {
- exception = ex.createTimeoutException();
- throw exception;
- }
- catch (Exception ex)
- {
- exception = ex;
- throw exception;
- }
- finally
- {
- getProtocol().stopSignal(this, exception);
- }
- }
-
- void setCorrelationID(int correlationID)
- {
- this.correlationID = correlationID;
- }
-
- void setBufferInputStream(BufferInputStream inputStream)
- {
- bufferInputStream = inputStream;
- }
-
- void setBufferOutputStream(BufferOutputStream outputStream)
- {
- bufferOutputStream = outputStream;
- }
-
- void doOutput(BufferOutputStream out) throws Exception
- {
- if (TRACER.isEnabled())
- {
- TRACER.format("================ {0}: {1}", getOutputMeaning(), this); //$NON-NLS-1$
- }
-
- OutputStream wrappedOutputStream = wrapOutputStream(out);
- ExtendedDataOutputStream extended = ExtendedDataOutputStream.wrap(wrappedOutputStream);
-
- try
- {
- doExtendedOutput(extended);
- }
- catch (Error ex)
- {
- throw ex;
- }
- catch (Exception ex)
- {
- throw ex;
- }
- finally
- {
- finishOutputStream(wrappedOutputStream);
- }
-
- out.flushWithEOS();
- }
-
- void doInput(BufferInputStream in) throws Exception
- {
- if (TRACER.isEnabled())
- {
- TRACER.format("================ {0}: {1}", getInputMeaning(), this); //$NON-NLS-1$
- }
-
- InputStream wrappedInputStream = wrapInputStream(in);
- ExtendedDataInputStream extended = ExtendedDataInputStream.wrap(wrappedInputStream);
-
- try
- {
- doExtendedInput(extended);
- }
- catch (Error ex)
- {
- throw ex;
- }
- catch (Exception ex)
- {
- throw ex;
- }
- finally
- {
- finishInputStream(wrappedInputStream);
- }
- }
-
- void doExtendedOutput(ExtendedDataOutputStream out) throws Exception
- {
- }
-
- void doExtendedInput(ExtendedDataInputStream in) throws Exception
- {
- }
-
- abstract String getOutputMeaning();
-
- abstract String getInputMeaning();
-}
+/*
+ * 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.signal;
+
+import org.eclipse.net4j.buffer.BufferInputStream;
+import org.eclipse.net4j.buffer.BufferOutputStream;
+import org.eclipse.net4j.util.ReflectUtil;
+import org.eclipse.net4j.util.io.ExtendedDataInputStream;
+import org.eclipse.net4j.util.io.ExtendedDataOutputStream;
+import org.eclipse.net4j.util.io.IOTimeoutException;
+import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
+import org.eclipse.net4j.util.om.trace.ContextTracer;
+
+import org.eclipse.internal.net4j.bundle.OM;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.text.MessageFormat;
+
+/**
+ * @author Eike Stepper
+ */
+public abstract class Signal implements Runnable
+{
+ /**
+ * @since 2.0
+ */
+ public static final long NO_TIMEOUT = BufferInputStream.NO_TIMEOUT;
+
+ private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_SIGNAL, Signal.class);
+
+ private SignalProtocol<?> protocol;
+
+ private short id;
+
+ private String name;
+
+ private int correlationID;
+
+ private BufferInputStream bufferInputStream;
+
+ private BufferOutputStream bufferOutputStream;
+
+ private Object currentStream;
+
+ /**
+ * Both implementation classes of a logical signal must have the same signalID. The signalID of a user signals must be
+ * equal to or greater than zero.
+ *
+ * @since 2.0
+ */
+ public Signal(SignalProtocol<?> protocol, short id, String name)
+ {
+ this.protocol = protocol;
+ this.id = id;
+ this.name = name;
+ }
+
+ /**
+ * @since 2.0
+ * @see #Signal(SignalProtocol, short, String)
+ */
+ public Signal(SignalProtocol<?> protocol, short id)
+ {
+ this(protocol, id, null);
+ }
+
+ /**
+ * @since 2.0
+ * @see #Signal(SignalProtocol, short, String)
+ */
+ public Signal(SignalProtocol<?> protocol, Enum<?> literal)
+ {
+ this(protocol, (short)literal.ordinal(), literal.name());
+ }
+
+ public SignalProtocol<?> getProtocol()
+ {
+ LifecycleUtil.checkActive(protocol);
+ return protocol;
+ }
+
+ /**
+ * Returns the short integer ID of this signal that is unique among all signals of the associated
+ * {@link #getProtocol() protocol}.
+ *
+ * @since 2.0
+ */
+ public final short getID()
+ {
+ return id;
+ }
+
+ /**
+ * @since 2.0
+ */
+ public String getName()
+ {
+ if (name == null)
+ {
+ // Needs no synchronization because any thread would set the same value.
+ name = ReflectUtil.getSimpleClassName(this);
+ }
+
+ return name;
+ }
+
+ /**
+ * @since 2.0
+ */
+ public final int getCorrelationID()
+ {
+ return correlationID;
+ }
+
+ /**
+ * @since 2.0
+ */
+ @Override
+ public String toString()
+ {
+ return MessageFormat.format("Signal[protocol={0}, id={1}, name={2}, correlation={3}]", getProtocol().getType(), //$NON-NLS-1$
+ getID(), getName(), getCorrelationID());
+ }
+
+ public final void run()
+ {
+ String threadName = null;
+
+ try
+ {
+ if (OM.SET_SIGNAL_THREAD_NAME)
+ {
+ threadName = getClass().getSimpleName();
+ Thread.currentThread().setName(threadName);
+ }
+
+ runSync();
+ }
+ catch (Exception ex)
+ {
+ if (getProtocol().isActive())
+ {
+ OM.LOG.error(ex);
+ }
+ else
+ {
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace("Exception while protocol is inactive", ex); //$NON-NLS-1$
+ }
+ }
+ }
+ finally
+ {
+ if (threadName != null)
+ {
+ Thread.currentThread().setName(threadName + "(FINISHED)"); //$NON-NLS-1$
+ }
+ }
+ }
+
+ protected final BufferInputStream getBufferInputStream()
+ {
+ return bufferInputStream;
+ }
+
+ protected final BufferOutputStream getBufferOutputStream()
+ {
+ return bufferOutputStream;
+ }
+
+ /**
+ * @since 2.0
+ */
+ protected final void flush() throws IOException
+ {
+ if (currentStream instanceof OutputStream)
+ {
+ ((OutputStream)currentStream).flush();
+ }
+ }
+
+ /**
+ * @since 2.0
+ */
+ protected InputStream getCurrentInputStream()
+ {
+ if (currentStream instanceof InputStream)
+ {
+ return (InputStream)currentStream;
+ }
+
+ return null;
+ }
+
+ /**
+ * @since 2.0
+ */
+ protected OutputStream getCurrentOutputStream()
+ {
+ if (currentStream instanceof OutputStream)
+ {
+ return (OutputStream)currentStream;
+ }
+
+ return null;
+ }
+
+ protected InputStream wrapInputStream(InputStream in) throws IOException
+ {
+ currentStream = getProtocol().wrapInputStream(in);
+ return (InputStream)currentStream;
+ }
+
+ protected OutputStream wrapOutputStream(OutputStream out) throws IOException
+ {
+ currentStream = getProtocol().wrapOutputStream(out);
+ return (OutputStream)currentStream;
+ }
+
+ protected void finishInputStream(InputStream in) throws IOException
+ {
+ currentStream = null;
+ getProtocol().finishInputStream(in);
+ }
+
+ protected void finishOutputStream(OutputStream out) throws IOException
+ {
+ currentStream = null;
+ getProtocol().finishOutputStream(out);
+ }
+
+ protected abstract void execute(BufferInputStream in, BufferOutputStream out) throws Exception;
+
+ void runSync() throws Exception
+ {
+ Exception exception = null;
+
+ try
+ {
+ execute(bufferInputStream, bufferOutputStream);
+ }
+ catch (IOTimeoutException ex) // Thrown from BufferInputStream
+ {
+ exception = ex.createTimeoutException();
+ throw exception;
+ }
+ catch (Exception ex)
+ {
+ exception = ex;
+ throw exception;
+ }
+ finally
+ {
+ getProtocol().stopSignal(this, exception);
+ }
+ }
+
+ void setCorrelationID(int correlationID)
+ {
+ this.correlationID = correlationID;
+ }
+
+ void setBufferInputStream(BufferInputStream inputStream)
+ {
+ bufferInputStream = inputStream;
+ }
+
+ void setBufferOutputStream(BufferOutputStream outputStream)
+ {
+ bufferOutputStream = outputStream;
+ }
+
+ void doOutput(BufferOutputStream out) throws Exception
+ {
+ if (TRACER.isEnabled())
+ {
+ TRACER.format("================ {0}: {1}", getOutputMeaning(), this); //$NON-NLS-1$
+ }
+
+ OutputStream wrappedOutputStream = wrapOutputStream(out);
+ ExtendedDataOutputStream extended = ExtendedDataOutputStream.wrap(wrappedOutputStream);
+
+ try
+ {
+ doExtendedOutput(extended);
+ }
+ catch (Error ex)
+ {
+ throw ex;
+ }
+ catch (Exception ex)
+ {
+ throw ex;
+ }
+ finally
+ {
+ finishOutputStream(wrappedOutputStream);
+ }
+
+ out.flushWithEOS();
+ }
+
+ void doInput(BufferInputStream in) throws Exception
+ {
+ if (TRACER.isEnabled())
+ {
+ TRACER.format("================ {0}: {1}", getInputMeaning(), this); //$NON-NLS-1$
+ }
+
+ InputStream wrappedInputStream = wrapInputStream(in);
+ ExtendedDataInputStream extended = ExtendedDataInputStream.wrap(wrappedInputStream);
+
+ try
+ {
+ doExtendedInput(extended);
+ }
+ catch (Error ex)
+ {
+ throw ex;
+ }
+ catch (Exception ex)
+ {
+ throw ex;
+ }
+ finally
+ {
+ finishInputStream(wrappedInputStream);
+ }
+ }
+
+ void doExtendedOutput(ExtendedDataOutputStream out) throws Exception
+ {
+ }
+
+ void doExtendedInput(ExtendedDataInputStream in) throws Exception
+ {
+ }
+
+ abstract String getOutputMeaning();
+
+ abstract String getInputMeaning();
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/SignalActor.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/SignalActor.java
index 37b40a72ee..8223b337ef 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/SignalActor.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/SignalActor.java
@@ -1,67 +1,67 @@
-/*
- * 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.signal;
-
-import org.eclipse.net4j.buffer.BufferInputStream;
-import org.eclipse.net4j.buffer.BufferOutputStream;
-
-/**
- * @author Eike Stepper
- */
-public abstract class SignalActor extends Signal
-{
- /**
- * @since 2.0
- */
- public SignalActor(SignalProtocol<?> protocol, short id, String name)
- {
- super(protocol, id, name);
- setCorrelationID(protocol.getNextCorrelationID());
- }
-
- /**
- * @since 2.0
- */
- public SignalActor(SignalProtocol<?> protocol, short id)
- {
- super(protocol, id);
- setCorrelationID(protocol.getNextCorrelationID());
- }
-
- /**
- * @since 2.0
- */
- public SignalActor(SignalProtocol<?> protocol, Enum<?> literal)
- {
- super(protocol, literal);
- setCorrelationID(protocol.getNextCorrelationID());
- }
-
- @Override
- protected final void execute(BufferInputStream in, BufferOutputStream out) throws Exception
- {
- doExecute(in, out);
- }
-
- abstract void doExecute(BufferInputStream in, BufferOutputStream out) throws Exception;
-
- @Override
- String getInputMeaning()
- {
- return "Confirming"; //$NON-NLS-1$
- }
-
- @Override
- String getOutputMeaning()
- {
- return "Requesting"; //$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.signal;
+
+import org.eclipse.net4j.buffer.BufferInputStream;
+import org.eclipse.net4j.buffer.BufferOutputStream;
+
+/**
+ * @author Eike Stepper
+ */
+public abstract class SignalActor extends Signal
+{
+ /**
+ * @since 2.0
+ */
+ public SignalActor(SignalProtocol<?> protocol, short id, String name)
+ {
+ super(protocol, id, name);
+ setCorrelationID(protocol.getNextCorrelationID());
+ }
+
+ /**
+ * @since 2.0
+ */
+ public SignalActor(SignalProtocol<?> protocol, short id)
+ {
+ super(protocol, id);
+ setCorrelationID(protocol.getNextCorrelationID());
+ }
+
+ /**
+ * @since 2.0
+ */
+ public SignalActor(SignalProtocol<?> protocol, Enum<?> literal)
+ {
+ super(protocol, literal);
+ setCorrelationID(protocol.getNextCorrelationID());
+ }
+
+ @Override
+ protected final void execute(BufferInputStream in, BufferOutputStream out) throws Exception
+ {
+ doExecute(in, out);
+ }
+
+ abstract void doExecute(BufferInputStream in, BufferOutputStream out) throws Exception;
+
+ @Override
+ String getInputMeaning()
+ {
+ return "Confirming"; //$NON-NLS-1$
+ }
+
+ @Override
+ String getOutputMeaning()
+ {
+ return "Requesting"; //$NON-NLS-1$
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/SignalCounter.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/SignalCounter.java
index 42b4776fa4..235a1f9568 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/SignalCounter.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/SignalCounter.java
@@ -1,56 +1,56 @@
-/*
- * 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.signal;
-
-import org.eclipse.net4j.util.collection.HashBag;
-import org.eclipse.net4j.util.event.IEvent;
-import org.eclipse.net4j.util.event.IListener;
-
-/**
- * @author Eike Stepper
- * @since 3.0
- */
-public final class SignalCounter implements IListener
-{
- private HashBag<Class<? extends Signal>> signals = new HashBag<Class<? extends Signal>>();
-
- public SignalCounter()
- {
- }
-
- public int getCountFor(Class<? extends Signal> signal)
- {
- synchronized (signals)
- {
- return signals.getCounterFor(signal);
- }
- }
-
- public void clearCounts()
- {
- synchronized (signals)
- {
- signals.clear();
- }
- }
-
- public void notifyEvent(IEvent event)
- {
- if (event instanceof SignalFinishedEvent)
- {
- synchronized (signals)
- {
- SignalFinishedEvent<?> e = (SignalFinishedEvent<?>)event;
- signals.add(e.getSignal().getClass());
- }
- }
- }
-}
+/*
+ * 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.signal;
+
+import org.eclipse.net4j.util.collection.HashBag;
+import org.eclipse.net4j.util.event.IEvent;
+import org.eclipse.net4j.util.event.IListener;
+
+/**
+ * @author Eike Stepper
+ * @since 3.0
+ */
+public final class SignalCounter implements IListener
+{
+ private HashBag<Class<? extends Signal>> signals = new HashBag<Class<? extends Signal>>();
+
+ public SignalCounter()
+ {
+ }
+
+ public int getCountFor(Class<? extends Signal> signal)
+ {
+ synchronized (signals)
+ {
+ return signals.getCounterFor(signal);
+ }
+ }
+
+ public void clearCounts()
+ {
+ synchronized (signals)
+ {
+ signals.clear();
+ }
+ }
+
+ public void notifyEvent(IEvent event)
+ {
+ if (event instanceof SignalFinishedEvent)
+ {
+ synchronized (signals)
+ {
+ SignalFinishedEvent<?> e = (SignalFinishedEvent<?>)event;
+ signals.add(e.getSignal().getClass());
+ }
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/SignalFinishedEvent.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/SignalFinishedEvent.java
index 7953e4d470..93f5a37a40 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/SignalFinishedEvent.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/SignalFinishedEvent.java
@@ -1,64 +1,64 @@
-/*
- * 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.signal;
-
-import org.eclipse.net4j.util.event.Event;
-
-/**
- * @author Eike Stepper
- * @since 3.0
- * @noextend This interface is not intended to be extended by clients.
- */
-public class SignalFinishedEvent<INFRA_STRUCTURE> extends Event
-{
- private static final long serialVersionUID = 1L;
-
- private Signal signal;
-
- private Exception exception;
-
- SignalFinishedEvent(ISignalProtocol<INFRA_STRUCTURE> source, Signal signal, Exception exception)
- {
- super(source);
- this.signal = signal;
- this.exception = exception;
- }
-
- @Override
- public ISignalProtocol<INFRA_STRUCTURE> getSource()
- {
- @SuppressWarnings("unchecked")
- ISignalProtocol<INFRA_STRUCTURE> source = (ISignalProtocol<INFRA_STRUCTURE>)super.getSource();
- return source;
- }
-
- public Signal getSignal()
- {
- return signal;
- }
-
- public Exception getException()
- {
- return exception;
- }
-
- @Override
- protected String formatAdditionalParameters()
- {
- String result = "signal=" + signal.getClass().getSimpleName();
- if (exception != null)
- {
- result += ", exception=" + exception.getClass().getSimpleName();
- }
-
- 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.signal;
+
+import org.eclipse.net4j.util.event.Event;
+
+/**
+ * @author Eike Stepper
+ * @since 3.0
+ * @noextend This interface is not intended to be extended by clients.
+ */
+public class SignalFinishedEvent<INFRA_STRUCTURE> extends Event
+{
+ private static final long serialVersionUID = 1L;
+
+ private Signal signal;
+
+ private Exception exception;
+
+ SignalFinishedEvent(ISignalProtocol<INFRA_STRUCTURE> source, Signal signal, Exception exception)
+ {
+ super(source);
+ this.signal = signal;
+ this.exception = exception;
+ }
+
+ @Override
+ public ISignalProtocol<INFRA_STRUCTURE> getSource()
+ {
+ @SuppressWarnings("unchecked")
+ ISignalProtocol<INFRA_STRUCTURE> source = (ISignalProtocol<INFRA_STRUCTURE>)super.getSource();
+ return source;
+ }
+
+ public Signal getSignal()
+ {
+ return signal;
+ }
+
+ public Exception getException()
+ {
+ return exception;
+ }
+
+ @Override
+ protected String formatAdditionalParameters()
+ {
+ String result = "signal=" + signal.getClass().getSimpleName();
+ if (exception != null)
+ {
+ result += ", exception=" + exception.getClass().getSimpleName();
+ }
+
+ return result;
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/SignalProtocol.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/SignalProtocol.java
index 0e941bb99a..2dd2c42768 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/SignalProtocol.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/SignalProtocol.java
@@ -1,636 +1,636 @@
-/*
- * 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
- * Andre Dietisheim - maintenance
- */
-package org.eclipse.net4j.signal;
-
-import org.eclipse.net4j.buffer.BufferInputStream;
-import org.eclipse.net4j.buffer.IBuffer;
-import org.eclipse.net4j.buffer.IBufferProvider;
-import org.eclipse.net4j.channel.ChannelOutputStream;
-import org.eclipse.net4j.channel.IChannel;
-import org.eclipse.net4j.connector.IConnector;
-import org.eclipse.net4j.util.WrappedException;
-import org.eclipse.net4j.util.event.Event;
-import org.eclipse.net4j.util.event.IListener;
-import org.eclipse.net4j.util.io.IORuntimeException;
-import org.eclipse.net4j.util.io.IStreamWrapper;
-import org.eclipse.net4j.util.io.StreamWrapperChain;
-import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
-import org.eclipse.net4j.util.om.log.OMLogger;
-import org.eclipse.net4j.util.om.trace.ContextTracer;
-
-import org.eclipse.internal.net4j.bundle.OM;
-
-import org.eclipse.spi.net4j.Protocol;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.nio.ByteBuffer;
-import java.text.MessageFormat;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * @author Eike Stepper
- */
-public class SignalProtocol<INFRA_STRUCTURE> extends Protocol<INFRA_STRUCTURE> implements
- ISignalProtocol<INFRA_STRUCTURE>
-{
- /**
- * @since 2.0
- */
- public static final short SIGNAL_REMOTE_EXCEPTION = -1;
-
- /**
- * @since 2.0
- */
- public static final short SIGNAL_MONITOR_CANCELED = -2;
-
- /**
- * @since 2.0
- */
- public static final short SIGNAL_MONITOR_PROGRESS = -3;
-
- /**
- * @since 4.1
- */
- public static final short SIGNAL_SET_TIMEOUT = -4;
-
- private static final int MIN_CORRELATION_ID = 1;
-
- private static final int MAX_CORRELATION_ID = Integer.MAX_VALUE;
-
- private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_SIGNAL, SignalProtocol.class);
-
- private static final ContextTracer STREAM_TRACER = new ContextTracer(OM.DEBUG_BUFFER_STREAM, SignalProtocol.class);
-
- private long timeout = DEFAULT_TIMEOUT;
-
- private IStreamWrapper streamWrapper;
-
- private Map<Integer, Signal> signals = new HashMap<Integer, Signal>();
-
- private int nextCorrelationID = MIN_CORRELATION_ID;
-
- private boolean failingOver;
-
- /**
- * @since 2.0
- */
- public SignalProtocol(String type)
- {
- super(type);
- }
-
- /**
- * @since 2.0
- */
- public long getTimeout()
- {
- return timeout;
- }
-
- /**
- * @since 2.0
- */
- public void setTimeout(long timeout)
- {
- long oldTimeout = this.timeout;
- handleSetTimeOut(timeout);
-
- if (oldTimeout != this.timeout && isActive())
- {
- sendSetTimeout();
- }
- }
-
- public IStreamWrapper getStreamWrapper()
- {
- return streamWrapper;
- }
-
- public void setStreamWrapper(IStreamWrapper streamWrapper)
- {
- this.streamWrapper = streamWrapper;
- }
-
- public void addStreamWrapper(IStreamWrapper streamWrapper)
- {
- if (this.streamWrapper == null)
- {
- this.streamWrapper = streamWrapper;
- }
- else
- {
- this.streamWrapper = new StreamWrapperChain(streamWrapper, this.streamWrapper);
- }
- }
-
- /**
- * @since 2.0
- */
- public IChannel open(IConnector connector)
- {
- return connector.openChannel(this);
- }
-
- /**
- * @since 2.0
- */
- public void close()
- {
- LifecycleUtil.deactivate(this, OMLogger.Level.DEBUG);
- }
-
- public boolean waitForSignals(long timeout)
- {
- synchronized (signals)
- {
- while (!signals.isEmpty())
- {
- try
- {
- signals.wait(timeout);
- }
- catch (InterruptedException ex)
- {
- return false;
- }
- }
- }
-
- return true;
- }
-
- /**
- * Handles a given (incoming) buffer. Creates a signal to act upon the given buffer or uses a previously created
- * signal.
- */
- public void handleBuffer(IBuffer buffer)
- {
- ByteBuffer byteBuffer = buffer.getByteBuffer();
- int correlationID = byteBuffer.getInt();
- if (TRACER.isEnabled())
- {
- TRACER.trace("Received buffer for correlation " + correlationID); //$NON-NLS-1$
- }
-
- Signal signal;
- boolean newSignalScheduled = false;
-
- synchronized (signals)
- {
- if (correlationID > 0)
- {
- // Incoming indication
- signal = signals.get(-correlationID);
- if (signal == null)
- {
- short signalID = byteBuffer.getShort();
- if (TRACER.isEnabled())
- {
- TRACER.trace("Got signalID: " + signalID); //$NON-NLS-1$
- }
-
- signal = provideSignalReactor(signalID);
- signal.setCorrelationID(-correlationID);
- signal.setBufferInputStream(new SignalInputStream(getTimeout()));
- if (signal instanceof IndicationWithResponse)
- {
- signal.setBufferOutputStream(new SignalOutputStream(-correlationID, signalID, false));
- }
-
- signals.put(-correlationID, signal);
- getExecutorService().execute(signal);
- newSignalScheduled = true;
- }
- }
- else
- {
- // Incoming confirmation
- signal = signals.get(-correlationID);
- }
- }
-
- if (signal != null) // Can be null after timeout
- {
- if (newSignalScheduled)
- {
- IListener[] listeners = getListeners();
- if (listeners != null)
- {
- fireEvent(new SignalScheduledEvent<INFRA_STRUCTURE>(this, signal), listeners);
- }
- }
-
- BufferInputStream inputStream = signal.getBufferInputStream();
- inputStream.handleBuffer(buffer);
- }
- else
- {
- if (TRACER.isEnabled())
- {
- TRACER.trace("Discarding buffer"); //$NON-NLS-1$
- }
-
- buffer.release();
- }
- }
-
- @Override
- public String toString()
- {
- return MessageFormat.format("SignalProtocol[{0}]", getType()); //$NON-NLS-1$
- }
-
- @Override
- protected void doAfterActivate() throws Exception
- {
- super.doAfterActivate();
-
- if (timeout != DEFAULT_TIMEOUT)
- {
- sendSetTimeout();
- }
- }
-
- @Override
- protected void doBeforeDeactivate() throws Exception
- {
- synchronized (signals)
- {
- // Wait at most 10 seconds for running signals to finish
- int waitMillis = 10 * 1000;
- long stop = System.currentTimeMillis() + waitMillis;
- while (!signals.isEmpty() && System.currentTimeMillis() < stop)
- {
- signals.wait(1000L);
- }
- }
- }
-
- @Override
- protected void doDeactivate() throws Exception
- {
- synchronized (signals)
- {
- signals.clear();
- }
-
- IChannel channel = getChannel();
- if (channel != null)
- {
- channel.close();
- setChannel(null);
- }
-
- super.doDeactivate();
- }
-
- @Override
- protected void handleChannelDeactivation()
- {
- if (!failingOver)
- {
- super.handleChannelDeactivation();
- }
- }
-
- protected final SignalReactor provideSignalReactor(short signalID)
- {
- checkActive();
- switch (signalID)
- {
- case SIGNAL_REMOTE_EXCEPTION:
- return new RemoteExceptionIndication(this);
-
- case SIGNAL_MONITOR_CANCELED:
- return new MonitorCanceledIndication(this);
-
- case SIGNAL_MONITOR_PROGRESS:
- return new MonitorProgressIndication(this);
-
- case SIGNAL_SET_TIMEOUT:
- return new SetTimeoutIndication(this);
-
- default:
- SignalReactor signal = createSignalReactor(signalID);
- if (signal == null)
- {
- throw new IllegalArgumentException("Invalid signalID " + signalID); //$NON-NLS-1$
- }
-
- return signal;
- }
- }
-
- /**
- * Returns a new signal instance to serve the given signal ID or <code>null</code> if the signal ID is invalid/unknown
- * for this protocol.
- */
- protected SignalReactor createSignalReactor(short signalID)
- {
- return null;
- }
-
- /**
- * Returns <code>true</code> by default, override to change this behaviour.
- *
- * @since 4.1
- */
- protected boolean isSendingTimeoutChanges()
- {
- return true;
- }
-
- synchronized int getNextCorrelationID()
- {
- int correlationID = nextCorrelationID;
- if (nextCorrelationID == MAX_CORRELATION_ID)
- {
- if (TRACER.isEnabled())
- {
- TRACER.trace("Correlation ID wrap-around"); //$NON-NLS-1$
- }
-
- nextCorrelationID = MIN_CORRELATION_ID;
- }
- else
- {
- ++nextCorrelationID;
- }
-
- return correlationID;
- }
-
- InputStream wrapInputStream(InputStream in) throws IOException
- {
- if (streamWrapper != null)
- {
- in = streamWrapper.wrapInputStream(in);
- }
-
- return in;
- }
-
- OutputStream wrapOutputStream(OutputStream out) throws IOException
- {
- if (streamWrapper != null)
- {
- out = streamWrapper.wrapOutputStream(out);
- }
-
- return out;
- }
-
- void finishInputStream(InputStream in) throws IOException
- {
- if (streamWrapper != null)
- {
- streamWrapper.finishInputStream(in);
- }
- }
-
- void finishOutputStream(OutputStream out) throws IOException
- {
- if (streamWrapper != null)
- {
- streamWrapper.finishOutputStream(out);
- }
- }
-
- void startSignal(SignalActor signalActor, long timeout) throws Exception
- {
- checkArg(signalActor.getProtocol() == this, "Wrong protocol"); //$NON-NLS-1$
- short signalID = signalActor.getID();
- int correlationID = signalActor.getCorrelationID();
- signalActor.setBufferOutputStream(new SignalOutputStream(correlationID, signalID, true));
- if (signalActor instanceof RequestWithConfirmation<?>)
- {
- signalActor.setBufferInputStream(new SignalInputStream(timeout));
- }
-
- synchronized (signals)
- {
- signals.put(correlationID, signalActor);
- }
-
- IListener[] listeners = getListeners();
- if (listeners != null)
- {
- fireEvent(new SignalScheduledEvent<INFRA_STRUCTURE>(this, signalActor), listeners);
- }
-
- signalActor.runSync();
- }
-
- void stopSignal(Signal signal, Exception exception)
- {
- int correlationID = signal.getCorrelationID();
- synchronized (signals)
- {
- signals.remove(correlationID);
- signals.notifyAll();
- }
-
- IListener[] listeners = getListeners();
- if (listeners != null)
- {
- fireEvent(new SignalFinishedEvent<INFRA_STRUCTURE>(this, signal, exception), listeners);
- }
- }
-
- void handleRemoteException(int correlationID, Throwable t, boolean responding)
- {
- synchronized (signals)
- {
- Signal signal = signals.remove(correlationID);
- if (signal instanceof RequestWithConfirmation<?>)
- {
- RequestWithConfirmation<?> request = (RequestWithConfirmation<?>)signal;
- request.setRemoteException(t, responding);
- }
-
- signals.notifyAll();
- }
- }
-
- void handleMonitorProgress(int correlationID, double totalWork, double work)
- {
- synchronized (signals)
- {
- Signal signal = signals.get(correlationID);
- if (signal instanceof RequestWithMonitoring<?>)
- {
- RequestWithMonitoring<?> request = (RequestWithMonitoring<?>)signal;
- request.setMonitorProgress(totalWork, work);
- }
- }
- }
-
- void handleMonitorCanceled(int correlationID)
- {
- synchronized (signals)
- {
- Signal signal = signals.get(correlationID);
- if (signal instanceof IndicationWithMonitoring)
- {
- IndicationWithMonitoring indication = (IndicationWithMonitoring)signal;
- indication.setMonitorCanceled();
- }
- }
- }
-
- void handleSetTimeOut(long timeout)
- {
- long oldTimeout = this.timeout;
- if (oldTimeout != timeout)
- {
- this.timeout = timeout;
- fireEvent(new TimeoutChangedEvent(this, oldTimeout, timeout));
- }
- }
-
- void sendSetTimeout()
- {
- if (isSendingTimeoutChanges())
- {
- try
- {
- new SetTimeoutRequest(this, this.timeout).send();
- }
- catch (Exception ex)
- {
- throw WrappedException.wrap(ex);
- }
- }
- }
-
- /**
- * @author Eike Stepper
- * @since 4.1
- */
- public static final class TimeoutChangedEvent extends Event
- {
- private static final long serialVersionUID = 1L;
-
- private long oldTimeout;
-
- private long newTimeout;
-
- private TimeoutChangedEvent(ISignalProtocol<?> source, long oldTimeout, long newTimeout)
- {
- super(source);
- this.oldTimeout = oldTimeout;
- this.newTimeout = newTimeout;
- }
-
- @Override
- public SignalProtocol<?> getSource()
- {
- return (SignalProtocol<?>)super.getSource();
- }
-
- public long getOldTimeout()
- {
- return oldTimeout;
- }
-
- public long getNewTimeout()
- {
- return newTimeout;
- }
-
- @Override
- public String toString()
- {
- return "TimeoutChangedEvent [oldTimeout=" + oldTimeout + ", newTimeout=" + newTimeout + ", source=" + source
- + "]";
- }
-
- }
-
- /**
- * @author Eike Stepper
- */
- class SignalInputStream extends BufferInputStream
- {
- private long timeout;
-
- public SignalInputStream(long timeout)
- {
- this.timeout = timeout;
- }
-
- @Override
- public long getMillisBeforeTimeout()
- {
- return timeout;
- }
- }
-
- /**
- * @author Eike Stepper
- */
- class SignalOutputStream extends ChannelOutputStream
- {
- public SignalOutputStream(final int correlationID, final short signalID, final boolean addSignalID)
- {
- super(getChannel(), new IBufferProvider()
- {
- private IBufferProvider delegate = getBufferProvider();
-
- private boolean firstBuffer = addSignalID;
-
- public short getBufferCapacity()
- {
- return delegate.getBufferCapacity();
- }
-
- public IBuffer provideBuffer()
- {
- IChannel channel = getChannel();
- if (channel == null)
- {
- throw new IORuntimeException("No channel for protocol " + SignalProtocol.this); //$NON-NLS-1$
- }
-
- IBuffer buffer = delegate.provideBuffer();
- ByteBuffer byteBuffer = buffer.startPutting(channel.getID());
- if (STREAM_TRACER.isEnabled())
- {
- STREAM_TRACER.trace("Providing buffer for correlation " + correlationID); //$NON-NLS-1$
- }
-
- byteBuffer.putInt(correlationID);
- if (firstBuffer)
- {
- if (SignalProtocol.TRACER.isEnabled())
- {
- STREAM_TRACER.trace("Put signal id " + signalID); //$NON-NLS-1$
- }
-
- byteBuffer.putShort(signalID);
- }
-
- firstBuffer = false;
- return buffer;
- }
-
- public void retainBuffer(IBuffer buffer)
- {
- delegate.retainBuffer(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
+ * Andre Dietisheim - maintenance
+ */
+package org.eclipse.net4j.signal;
+
+import org.eclipse.net4j.buffer.BufferInputStream;
+import org.eclipse.net4j.buffer.IBuffer;
+import org.eclipse.net4j.buffer.IBufferProvider;
+import org.eclipse.net4j.channel.ChannelOutputStream;
+import org.eclipse.net4j.channel.IChannel;
+import org.eclipse.net4j.connector.IConnector;
+import org.eclipse.net4j.util.WrappedException;
+import org.eclipse.net4j.util.event.Event;
+import org.eclipse.net4j.util.event.IListener;
+import org.eclipse.net4j.util.io.IORuntimeException;
+import org.eclipse.net4j.util.io.IStreamWrapper;
+import org.eclipse.net4j.util.io.StreamWrapperChain;
+import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
+import org.eclipse.net4j.util.om.log.OMLogger;
+import org.eclipse.net4j.util.om.trace.ContextTracer;
+
+import org.eclipse.internal.net4j.bundle.OM;
+
+import org.eclipse.spi.net4j.Protocol;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.ByteBuffer;
+import java.text.MessageFormat;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author Eike Stepper
+ */
+public class SignalProtocol<INFRA_STRUCTURE> extends Protocol<INFRA_STRUCTURE> implements
+ ISignalProtocol<INFRA_STRUCTURE>
+{
+ /**
+ * @since 2.0
+ */
+ public static final short SIGNAL_REMOTE_EXCEPTION = -1;
+
+ /**
+ * @since 2.0
+ */
+ public static final short SIGNAL_MONITOR_CANCELED = -2;
+
+ /**
+ * @since 2.0
+ */
+ public static final short SIGNAL_MONITOR_PROGRESS = -3;
+
+ /**
+ * @since 4.1
+ */
+ public static final short SIGNAL_SET_TIMEOUT = -4;
+
+ private static final int MIN_CORRELATION_ID = 1;
+
+ private static final int MAX_CORRELATION_ID = Integer.MAX_VALUE;
+
+ private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_SIGNAL, SignalProtocol.class);
+
+ private static final ContextTracer STREAM_TRACER = new ContextTracer(OM.DEBUG_BUFFER_STREAM, SignalProtocol.class);
+
+ private long timeout = DEFAULT_TIMEOUT;
+
+ private IStreamWrapper streamWrapper;
+
+ private Map<Integer, Signal> signals = new HashMap<Integer, Signal>();
+
+ private int nextCorrelationID = MIN_CORRELATION_ID;
+
+ private boolean failingOver;
+
+ /**
+ * @since 2.0
+ */
+ public SignalProtocol(String type)
+ {
+ super(type);
+ }
+
+ /**
+ * @since 2.0
+ */
+ public long getTimeout()
+ {
+ return timeout;
+ }
+
+ /**
+ * @since 2.0
+ */
+ public void setTimeout(long timeout)
+ {
+ long oldTimeout = this.timeout;
+ handleSetTimeOut(timeout);
+
+ if (oldTimeout != this.timeout && isActive())
+ {
+ sendSetTimeout();
+ }
+ }
+
+ public IStreamWrapper getStreamWrapper()
+ {
+ return streamWrapper;
+ }
+
+ public void setStreamWrapper(IStreamWrapper streamWrapper)
+ {
+ this.streamWrapper = streamWrapper;
+ }
+
+ public void addStreamWrapper(IStreamWrapper streamWrapper)
+ {
+ if (this.streamWrapper == null)
+ {
+ this.streamWrapper = streamWrapper;
+ }
+ else
+ {
+ this.streamWrapper = new StreamWrapperChain(streamWrapper, this.streamWrapper);
+ }
+ }
+
+ /**
+ * @since 2.0
+ */
+ public IChannel open(IConnector connector)
+ {
+ return connector.openChannel(this);
+ }
+
+ /**
+ * @since 2.0
+ */
+ public void close()
+ {
+ LifecycleUtil.deactivate(this, OMLogger.Level.DEBUG);
+ }
+
+ public boolean waitForSignals(long timeout)
+ {
+ synchronized (signals)
+ {
+ while (!signals.isEmpty())
+ {
+ try
+ {
+ signals.wait(timeout);
+ }
+ catch (InterruptedException ex)
+ {
+ return false;
+ }
+ }
+ }
+
+ return true;
+ }
+
+ /**
+ * Handles a given (incoming) buffer. Creates a signal to act upon the given buffer or uses a previously created
+ * signal.
+ */
+ public void handleBuffer(IBuffer buffer)
+ {
+ ByteBuffer byteBuffer = buffer.getByteBuffer();
+ int correlationID = byteBuffer.getInt();
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace("Received buffer for correlation " + correlationID); //$NON-NLS-1$
+ }
+
+ Signal signal;
+ boolean newSignalScheduled = false;
+
+ synchronized (signals)
+ {
+ if (correlationID > 0)
+ {
+ // Incoming indication
+ signal = signals.get(-correlationID);
+ if (signal == null)
+ {
+ short signalID = byteBuffer.getShort();
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace("Got signalID: " + signalID); //$NON-NLS-1$
+ }
+
+ signal = provideSignalReactor(signalID);
+ signal.setCorrelationID(-correlationID);
+ signal.setBufferInputStream(new SignalInputStream(getTimeout()));
+ if (signal instanceof IndicationWithResponse)
+ {
+ signal.setBufferOutputStream(new SignalOutputStream(-correlationID, signalID, false));
+ }
+
+ signals.put(-correlationID, signal);
+ getExecutorService().execute(signal);
+ newSignalScheduled = true;
+ }
+ }
+ else
+ {
+ // Incoming confirmation
+ signal = signals.get(-correlationID);
+ }
+ }
+
+ if (signal != null) // Can be null after timeout
+ {
+ if (newSignalScheduled)
+ {
+ IListener[] listeners = getListeners();
+ if (listeners != null)
+ {
+ fireEvent(new SignalScheduledEvent<INFRA_STRUCTURE>(this, signal), listeners);
+ }
+ }
+
+ BufferInputStream inputStream = signal.getBufferInputStream();
+ inputStream.handleBuffer(buffer);
+ }
+ else
+ {
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace("Discarding buffer"); //$NON-NLS-1$
+ }
+
+ buffer.release();
+ }
+ }
+
+ @Override
+ public String toString()
+ {
+ return MessageFormat.format("SignalProtocol[{0}]", getType()); //$NON-NLS-1$
+ }
+
+ @Override
+ protected void doAfterActivate() throws Exception
+ {
+ super.doAfterActivate();
+
+ if (timeout != DEFAULT_TIMEOUT)
+ {
+ sendSetTimeout();
+ }
+ }
+
+ @Override
+ protected void doBeforeDeactivate() throws Exception
+ {
+ synchronized (signals)
+ {
+ // Wait at most 10 seconds for running signals to finish
+ int waitMillis = 10 * 1000;
+ long stop = System.currentTimeMillis() + waitMillis;
+ while (!signals.isEmpty() && System.currentTimeMillis() < stop)
+ {
+ signals.wait(1000L);
+ }
+ }
+ }
+
+ @Override
+ protected void doDeactivate() throws Exception
+ {
+ synchronized (signals)
+ {
+ signals.clear();
+ }
+
+ IChannel channel = getChannel();
+ if (channel != null)
+ {
+ channel.close();
+ setChannel(null);
+ }
+
+ super.doDeactivate();
+ }
+
+ @Override
+ protected void handleChannelDeactivation()
+ {
+ if (!failingOver)
+ {
+ super.handleChannelDeactivation();
+ }
+ }
+
+ protected final SignalReactor provideSignalReactor(short signalID)
+ {
+ checkActive();
+ switch (signalID)
+ {
+ case SIGNAL_REMOTE_EXCEPTION:
+ return new RemoteExceptionIndication(this);
+
+ case SIGNAL_MONITOR_CANCELED:
+ return new MonitorCanceledIndication(this);
+
+ case SIGNAL_MONITOR_PROGRESS:
+ return new MonitorProgressIndication(this);
+
+ case SIGNAL_SET_TIMEOUT:
+ return new SetTimeoutIndication(this);
+
+ default:
+ SignalReactor signal = createSignalReactor(signalID);
+ if (signal == null)
+ {
+ throw new IllegalArgumentException("Invalid signalID " + signalID); //$NON-NLS-1$
+ }
+
+ return signal;
+ }
+ }
+
+ /**
+ * Returns a new signal instance to serve the given signal ID or <code>null</code> if the signal ID is invalid/unknown
+ * for this protocol.
+ */
+ protected SignalReactor createSignalReactor(short signalID)
+ {
+ return null;
+ }
+
+ /**
+ * Returns <code>true</code> by default, override to change this behaviour.
+ *
+ * @since 4.1
+ */
+ protected boolean isSendingTimeoutChanges()
+ {
+ return true;
+ }
+
+ synchronized int getNextCorrelationID()
+ {
+ int correlationID = nextCorrelationID;
+ if (nextCorrelationID == MAX_CORRELATION_ID)
+ {
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace("Correlation ID wrap-around"); //$NON-NLS-1$
+ }
+
+ nextCorrelationID = MIN_CORRELATION_ID;
+ }
+ else
+ {
+ ++nextCorrelationID;
+ }
+
+ return correlationID;
+ }
+
+ InputStream wrapInputStream(InputStream in) throws IOException
+ {
+ if (streamWrapper != null)
+ {
+ in = streamWrapper.wrapInputStream(in);
+ }
+
+ return in;
+ }
+
+ OutputStream wrapOutputStream(OutputStream out) throws IOException
+ {
+ if (streamWrapper != null)
+ {
+ out = streamWrapper.wrapOutputStream(out);
+ }
+
+ return out;
+ }
+
+ void finishInputStream(InputStream in) throws IOException
+ {
+ if (streamWrapper != null)
+ {
+ streamWrapper.finishInputStream(in);
+ }
+ }
+
+ void finishOutputStream(OutputStream out) throws IOException
+ {
+ if (streamWrapper != null)
+ {
+ streamWrapper.finishOutputStream(out);
+ }
+ }
+
+ void startSignal(SignalActor signalActor, long timeout) throws Exception
+ {
+ checkArg(signalActor.getProtocol() == this, "Wrong protocol"); //$NON-NLS-1$
+ short signalID = signalActor.getID();
+ int correlationID = signalActor.getCorrelationID();
+ signalActor.setBufferOutputStream(new SignalOutputStream(correlationID, signalID, true));
+ if (signalActor instanceof RequestWithConfirmation<?>)
+ {
+ signalActor.setBufferInputStream(new SignalInputStream(timeout));
+ }
+
+ synchronized (signals)
+ {
+ signals.put(correlationID, signalActor);
+ }
+
+ IListener[] listeners = getListeners();
+ if (listeners != null)
+ {
+ fireEvent(new SignalScheduledEvent<INFRA_STRUCTURE>(this, signalActor), listeners);
+ }
+
+ signalActor.runSync();
+ }
+
+ void stopSignal(Signal signal, Exception exception)
+ {
+ int correlationID = signal.getCorrelationID();
+ synchronized (signals)
+ {
+ signals.remove(correlationID);
+ signals.notifyAll();
+ }
+
+ IListener[] listeners = getListeners();
+ if (listeners != null)
+ {
+ fireEvent(new SignalFinishedEvent<INFRA_STRUCTURE>(this, signal, exception), listeners);
+ }
+ }
+
+ void handleRemoteException(int correlationID, Throwable t, boolean responding)
+ {
+ synchronized (signals)
+ {
+ Signal signal = signals.remove(correlationID);
+ if (signal instanceof RequestWithConfirmation<?>)
+ {
+ RequestWithConfirmation<?> request = (RequestWithConfirmation<?>)signal;
+ request.setRemoteException(t, responding);
+ }
+
+ signals.notifyAll();
+ }
+ }
+
+ void handleMonitorProgress(int correlationID, double totalWork, double work)
+ {
+ synchronized (signals)
+ {
+ Signal signal = signals.get(correlationID);
+ if (signal instanceof RequestWithMonitoring<?>)
+ {
+ RequestWithMonitoring<?> request = (RequestWithMonitoring<?>)signal;
+ request.setMonitorProgress(totalWork, work);
+ }
+ }
+ }
+
+ void handleMonitorCanceled(int correlationID)
+ {
+ synchronized (signals)
+ {
+ Signal signal = signals.get(correlationID);
+ if (signal instanceof IndicationWithMonitoring)
+ {
+ IndicationWithMonitoring indication = (IndicationWithMonitoring)signal;
+ indication.setMonitorCanceled();
+ }
+ }
+ }
+
+ void handleSetTimeOut(long timeout)
+ {
+ long oldTimeout = this.timeout;
+ if (oldTimeout != timeout)
+ {
+ this.timeout = timeout;
+ fireEvent(new TimeoutChangedEvent(this, oldTimeout, timeout));
+ }
+ }
+
+ void sendSetTimeout()
+ {
+ if (isSendingTimeoutChanges())
+ {
+ try
+ {
+ new SetTimeoutRequest(this, this.timeout).send();
+ }
+ catch (Exception ex)
+ {
+ throw WrappedException.wrap(ex);
+ }
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ * @since 4.1
+ */
+ public static final class TimeoutChangedEvent extends Event
+ {
+ private static final long serialVersionUID = 1L;
+
+ private long oldTimeout;
+
+ private long newTimeout;
+
+ private TimeoutChangedEvent(ISignalProtocol<?> source, long oldTimeout, long newTimeout)
+ {
+ super(source);
+ this.oldTimeout = oldTimeout;
+ this.newTimeout = newTimeout;
+ }
+
+ @Override
+ public SignalProtocol<?> getSource()
+ {
+ return (SignalProtocol<?>)super.getSource();
+ }
+
+ public long getOldTimeout()
+ {
+ return oldTimeout;
+ }
+
+ public long getNewTimeout()
+ {
+ return newTimeout;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "TimeoutChangedEvent [oldTimeout=" + oldTimeout + ", newTimeout=" + newTimeout + ", source=" + source
+ + "]";
+ }
+
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ class SignalInputStream extends BufferInputStream
+ {
+ private long timeout;
+
+ public SignalInputStream(long timeout)
+ {
+ this.timeout = timeout;
+ }
+
+ @Override
+ public long getMillisBeforeTimeout()
+ {
+ return timeout;
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ class SignalOutputStream extends ChannelOutputStream
+ {
+ public SignalOutputStream(final int correlationID, final short signalID, final boolean addSignalID)
+ {
+ super(getChannel(), new IBufferProvider()
+ {
+ private IBufferProvider delegate = getBufferProvider();
+
+ private boolean firstBuffer = addSignalID;
+
+ public short getBufferCapacity()
+ {
+ return delegate.getBufferCapacity();
+ }
+
+ public IBuffer provideBuffer()
+ {
+ IChannel channel = getChannel();
+ if (channel == null)
+ {
+ throw new IORuntimeException("No channel for protocol " + SignalProtocol.this); //$NON-NLS-1$
+ }
+
+ IBuffer buffer = delegate.provideBuffer();
+ ByteBuffer byteBuffer = buffer.startPutting(channel.getID());
+ if (STREAM_TRACER.isEnabled())
+ {
+ STREAM_TRACER.trace("Providing buffer for correlation " + correlationID); //$NON-NLS-1$
+ }
+
+ byteBuffer.putInt(correlationID);
+ if (firstBuffer)
+ {
+ if (SignalProtocol.TRACER.isEnabled())
+ {
+ STREAM_TRACER.trace("Put signal id " + signalID); //$NON-NLS-1$
+ }
+
+ byteBuffer.putShort(signalID);
+ }
+
+ firstBuffer = false;
+ return buffer;
+ }
+
+ public void retainBuffer(IBuffer buffer)
+ {
+ delegate.retainBuffer(buffer);
+ }
+ });
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/SignalReactor.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/SignalReactor.java
index 08f57c95f3..68ef475cd9 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/SignalReactor.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/SignalReactor.java
@@ -1,53 +1,53 @@
-/*
- * 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.signal;
-
-/**
- * @author Eike Stepper
- */
-public abstract class SignalReactor extends Signal
-{
- /**
- * @since 2.0
- */
- public SignalReactor(SignalProtocol<?> protocol, short id, String name)
- {
- super(protocol, id, name);
- }
-
- /**
- * @since 2.0
- */
- public SignalReactor(SignalProtocol<?> protocol, short signalID)
- {
- super(protocol, signalID);
- }
-
- /**
- * @since 2.0
- */
- public SignalReactor(SignalProtocol<?> protocol, Enum<?> literal)
- {
- super(protocol, literal);
- }
-
- @Override
- String getInputMeaning()
- {
- return "Indicating"; //$NON-NLS-1$
- }
-
- @Override
- String getOutputMeaning()
- {
- return "Responding"; //$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.signal;
+
+/**
+ * @author Eike Stepper
+ */
+public abstract class SignalReactor extends Signal
+{
+ /**
+ * @since 2.0
+ */
+ public SignalReactor(SignalProtocol<?> protocol, short id, String name)
+ {
+ super(protocol, id, name);
+ }
+
+ /**
+ * @since 2.0
+ */
+ public SignalReactor(SignalProtocol<?> protocol, short signalID)
+ {
+ super(protocol, signalID);
+ }
+
+ /**
+ * @since 2.0
+ */
+ public SignalReactor(SignalProtocol<?> protocol, Enum<?> literal)
+ {
+ super(protocol, literal);
+ }
+
+ @Override
+ String getInputMeaning()
+ {
+ return "Indicating"; //$NON-NLS-1$
+ }
+
+ @Override
+ String getOutputMeaning()
+ {
+ return "Responding"; //$NON-NLS-1$
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/SignalScheduledEvent.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/SignalScheduledEvent.java
index 44b6ed7a20..50b94bc846 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/SignalScheduledEvent.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/SignalScheduledEvent.java
@@ -1,50 +1,50 @@
-/*
- * 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.signal;
-
-import org.eclipse.net4j.util.event.Event;
-
-/**
- * @author Eike Stepper
- * @since 3.0
- * @noextend This interface is not intended to be extended by clients.
- */
-public class SignalScheduledEvent<INFRA_STRUCTURE> extends Event
-{
- private static final long serialVersionUID = 1L;
-
- private Signal signal;
-
- SignalScheduledEvent(ISignalProtocol<INFRA_STRUCTURE> source, Signal signal)
- {
- super(source);
- this.signal = signal;
- }
-
- @Override
- public ISignalProtocol<INFRA_STRUCTURE> getSource()
- {
- @SuppressWarnings("unchecked")
- ISignalProtocol<INFRA_STRUCTURE> source = (ISignalProtocol<INFRA_STRUCTURE>)super.getSource();
- return source;
- }
-
- public Signal getSignal()
- {
- return signal;
- }
-
- @Override
- protected String formatAdditionalParameters()
- {
- return "signal=" + signal.getClass().getSimpleName();
- }
-}
+/*
+ * 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.signal;
+
+import org.eclipse.net4j.util.event.Event;
+
+/**
+ * @author Eike Stepper
+ * @since 3.0
+ * @noextend This interface is not intended to be extended by clients.
+ */
+public class SignalScheduledEvent<INFRA_STRUCTURE> extends Event
+{
+ private static final long serialVersionUID = 1L;
+
+ private Signal signal;
+
+ SignalScheduledEvent(ISignalProtocol<INFRA_STRUCTURE> source, Signal signal)
+ {
+ super(source);
+ this.signal = signal;
+ }
+
+ @Override
+ public ISignalProtocol<INFRA_STRUCTURE> getSource()
+ {
+ @SuppressWarnings("unchecked")
+ ISignalProtocol<INFRA_STRUCTURE> source = (ISignalProtocol<INFRA_STRUCTURE>)super.getSource();
+ return source;
+ }
+
+ public Signal getSignal()
+ {
+ return signal;
+ }
+
+ @Override
+ protected String formatAdditionalParameters()
+ {
+ return "signal=" + signal.getClass().getSimpleName();
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/heartbeat/HeartBeatProtocol.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/heartbeat/HeartBeatProtocol.java
index 1f8c8bca90..ac235ec11c 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/heartbeat/HeartBeatProtocol.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/heartbeat/HeartBeatProtocol.java
@@ -1,352 +1,352 @@
-/*
- * 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.signal.heartbeat;
-
-import org.eclipse.net4j.channel.IChannelMultiplexer;
-import org.eclipse.net4j.connector.IConnector;
-import org.eclipse.net4j.signal.Indication;
-import org.eclipse.net4j.signal.Request;
-import org.eclipse.net4j.signal.SignalProtocol;
-import org.eclipse.net4j.signal.SignalReactor;
-import org.eclipse.net4j.util.WrappedException;
-import org.eclipse.net4j.util.concurrent.Timeouter;
-import org.eclipse.net4j.util.concurrent.TimerLifecycle;
-import org.eclipse.net4j.util.container.IElementProcessor;
-import org.eclipse.net4j.util.container.IManagedContainer;
-import org.eclipse.net4j.util.container.IPluginContainer;
-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.lifecycle.LifecycleUtil;
-import org.eclipse.net4j.util.om.log.OMLogger;
-
-import org.eclipse.internal.net4j.bundle.OM;
-
-import org.eclipse.spi.net4j.ServerProtocolFactory;
-
-import java.io.IOException;
-import java.util.Timer;
-import java.util.TimerTask;
-
-/**
- * @author Eike Stepper
- * @since 2.0
- */
-public class HeartBeatProtocol extends SignalProtocol<Object>
-{
- public static final String TYPE = "heartbeat"; //$NON-NLS-1$
-
- private static final short SIGNAL_START = 1;
-
- private static final short SIGNAL_HEART_BEAT = 2;
-
- private static final boolean HEART_BEAT = true;
-
- private Timeouter timeouter;
-
- private Timer timer;
-
- /**
- * @since 4.0
- */
- protected HeartBeatProtocol(String type, IConnector connector, Timer timer)
- {
- super(type);
- checkArg(timer, "timer"); //$NON-NLS-1$
- checkArg(connector, "connector"); //$NON-NLS-1$
- this.timer = timer;
- open(connector);
- }
-
- public HeartBeatProtocol(IConnector connector, Timer timer)
- {
- this(TYPE, connector, timer);
- }
-
- /**
- * @since 4.0
- */
- public HeartBeatProtocol(IConnector connector, IManagedContainer container)
- {
- this(connector, getDefaultTimer(container));
- }
-
- public HeartBeatProtocol(IConnector connector)
- {
- this(connector, IPluginContainer.INSTANCE);
- }
-
- public Timer getTimer()
- {
- return timer;
- }
-
- /**
- * Same as <code>start(rate, 2 * rate)</code>.
- *
- * @see #start(long, long)
- */
- public void start(final long rate)
- {
- start(rate, 2L * rate);
- }
-
- public void start(final long rate, long timeout)
- {
- checkActive();
- checkArg(rate > 0, "rate"); //$NON-NLS-1$
- checkArg(timeout >= rate, "timeout"); //$NON-NLS-1$
-
- try
- {
- new Request(this, SIGNAL_START, "Start") //$NON-NLS-1$
- {
- @Override
- protected void requesting(ExtendedDataOutputStream out) throws Exception
- {
- requestingStart(out, rate);
- }
- }.sendAsync();
- }
- catch (Exception ex)
- {
- throw WrappedException.wrap(ex);
- }
-
- if (timeouter == null)
- {
- timeouter = new Timeouter(getTimer(), timeout)
- {
- @Override
- protected void handleTimeout(long untouched)
- {
- HeartBeatProtocol.this.handleTimeout(untouched);
- }
- };
- }
- else
- {
- timeouter.setTimeout(timeout);
- timeouter.touch();
- }
- }
-
- @Override
- protected SignalReactor createSignalReactor(short signalID)
- {
- if (signalID == SIGNAL_HEART_BEAT)
- {
- return new Indication(HeartBeatProtocol.this, SIGNAL_HEART_BEAT, "HeartBeat") //$NON-NLS-1$
- {
- @Override
- protected void indicating(ExtendedDataInputStream in) throws Exception
- {
- checkState(in.readBoolean() == HEART_BEAT, "Invalid heart beat"); //$NON-NLS-1$
- timeouter.touch();
- }
- };
- }
-
- return null;
- }
-
- protected void handleTimeout(long untouched)
- {
- IChannelMultiplexer multiplexer = getChannel().getMultiplexer();
- LifecycleUtil.deactivate(multiplexer, OMLogger.Level.DEBUG);
- }
-
- @Override
- protected void doDeactivate() throws Exception
- {
- if (timeouter != null)
- {
- timeouter.dispose();
- timeouter = null;
- }
-
- super.doDeactivate();
- }
-
- /**
- * @since 4.0
- */
- protected void requestingStart(ExtendedDataOutputStream out, long rate) throws IOException
- {
- out.writeLong(rate);
- }
-
- public static Timer getDefaultTimer(IManagedContainer container)
- {
- return TimerLifecycle.DaemonFactory.getTimer(container, null);
- }
-
- /**
- * @author Eike Stepper
- */
- public static class Server extends SignalProtocol<Object>
- {
- private long heartBeatRate;
-
- private Timer heartBeatTimer;
-
- private TimerTask heartBeatTimerTask;
-
- /**
- * @since 4.0
- */
- protected Server(String type)
- {
- super(type);
- }
-
- public Server()
- {
- this(TYPE);
- }
-
- public Timer getHeartBeatTimer()
- {
- return heartBeatTimer;
- }
-
- public void setHeartBeatTimer(Timer heartBeatTimer)
- {
- checkInactive();
- this.heartBeatTimer = heartBeatTimer;
- }
-
- @Override
- protected SignalReactor createSignalReactor(short signalID)
- {
- if (signalID == SIGNAL_START)
- {
- return new Indication(Server.this, SIGNAL_START, "Start") //$NON-NLS-1$
- {
- @Override
- protected void indicating(ExtendedDataInputStream in) throws Exception
- {
- indicatingStart(in);
- }
- };
- }
-
- return null;
- }
-
- @Override
- protected void doBeforeActivate() throws Exception
- {
- super.doBeforeActivate();
- checkState(heartBeatTimer, "heartBeatTimer"); //$NON-NLS-1$
- }
-
- @Override
- protected void doDeactivate() throws Exception
- {
- cancelHeartBeatTask();
- super.doDeactivate();
- }
-
- /**
- * @since 4.0
- */
- protected void indicatingStart(ExtendedDataInputStream in) throws IOException
- {
- heartBeatRate = in.readLong();
- cancelHeartBeatTask();
- scheduleHeartBeatTask();
- }
-
- private void scheduleHeartBeatTask()
- {
- heartBeatTimerTask = new TimerTask()
- {
- @Override
- public void run()
- {
- try
- {
- new Request(Server.this, SIGNAL_HEART_BEAT, "HeartBeat") //$NON-NLS-1$
- {
- @Override
- protected void requesting(ExtendedDataOutputStream out) throws Exception
- {
- out.writeBoolean(HEART_BEAT);
- }
- }.sendAsync();
- }
- catch (Exception ex)
- {
- OM.LOG.error("HeartBeatProtocolTask failed", ex);
- }
- }
- };
-
- heartBeatTimer.schedule(heartBeatTimerTask, 0L, heartBeatRate);
- }
-
- private void cancelHeartBeatTask()
- {
- if (heartBeatTimerTask != null)
- {
- heartBeatTimerTask.cancel();
- heartBeatTimerTask = null;
- }
- }
-
- /**
- * @author Eike Stepper
- */
- public static class Factory extends ServerProtocolFactory
- {
- public Factory()
- {
- super(TYPE);
- }
-
- public Object create(String description) throws ProductCreationException
- {
- return new HeartBeatProtocol.Server();
- }
- }
-
- /**
- * @author Eike Stepper
- */
- public static class TimerInjector implements IElementProcessor
- {
- public TimerInjector()
- {
- }
-
- public Object process(IManagedContainer container, String productGroup, String factoryType, String description,
- Object element)
- {
- if (element instanceof Server)
- {
- Server server = (Server)element;
- if (server.getHeartBeatTimer() == null)
- {
- server.setHeartBeatTimer(getTimer(container));
- }
- }
-
- return element;
- }
-
- protected Timer getTimer(IManagedContainer container)
- {
- return getDefaultTimer(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.signal.heartbeat;
+
+import org.eclipse.net4j.channel.IChannelMultiplexer;
+import org.eclipse.net4j.connector.IConnector;
+import org.eclipse.net4j.signal.Indication;
+import org.eclipse.net4j.signal.Request;
+import org.eclipse.net4j.signal.SignalProtocol;
+import org.eclipse.net4j.signal.SignalReactor;
+import org.eclipse.net4j.util.WrappedException;
+import org.eclipse.net4j.util.concurrent.Timeouter;
+import org.eclipse.net4j.util.concurrent.TimerLifecycle;
+import org.eclipse.net4j.util.container.IElementProcessor;
+import org.eclipse.net4j.util.container.IManagedContainer;
+import org.eclipse.net4j.util.container.IPluginContainer;
+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.lifecycle.LifecycleUtil;
+import org.eclipse.net4j.util.om.log.OMLogger;
+
+import org.eclipse.internal.net4j.bundle.OM;
+
+import org.eclipse.spi.net4j.ServerProtocolFactory;
+
+import java.io.IOException;
+import java.util.Timer;
+import java.util.TimerTask;
+
+/**
+ * @author Eike Stepper
+ * @since 2.0
+ */
+public class HeartBeatProtocol extends SignalProtocol<Object>
+{
+ public static final String TYPE = "heartbeat"; //$NON-NLS-1$
+
+ private static final short SIGNAL_START = 1;
+
+ private static final short SIGNAL_HEART_BEAT = 2;
+
+ private static final boolean HEART_BEAT = true;
+
+ private Timeouter timeouter;
+
+ private Timer timer;
+
+ /**
+ * @since 4.0
+ */
+ protected HeartBeatProtocol(String type, IConnector connector, Timer timer)
+ {
+ super(type);
+ checkArg(timer, "timer"); //$NON-NLS-1$
+ checkArg(connector, "connector"); //$NON-NLS-1$
+ this.timer = timer;
+ open(connector);
+ }
+
+ public HeartBeatProtocol(IConnector connector, Timer timer)
+ {
+ this(TYPE, connector, timer);
+ }
+
+ /**
+ * @since 4.0
+ */
+ public HeartBeatProtocol(IConnector connector, IManagedContainer container)
+ {
+ this(connector, getDefaultTimer(container));
+ }
+
+ public HeartBeatProtocol(IConnector connector)
+ {
+ this(connector, IPluginContainer.INSTANCE);
+ }
+
+ public Timer getTimer()
+ {
+ return timer;
+ }
+
+ /**
+ * Same as <code>start(rate, 2 * rate)</code>.
+ *
+ * @see #start(long, long)
+ */
+ public void start(final long rate)
+ {
+ start(rate, 2L * rate);
+ }
+
+ public void start(final long rate, long timeout)
+ {
+ checkActive();
+ checkArg(rate > 0, "rate"); //$NON-NLS-1$
+ checkArg(timeout >= rate, "timeout"); //$NON-NLS-1$
+
+ try
+ {
+ new Request(this, SIGNAL_START, "Start") //$NON-NLS-1$
+ {
+ @Override
+ protected void requesting(ExtendedDataOutputStream out) throws Exception
+ {
+ requestingStart(out, rate);
+ }
+ }.sendAsync();
+ }
+ catch (Exception ex)
+ {
+ throw WrappedException.wrap(ex);
+ }
+
+ if (timeouter == null)
+ {
+ timeouter = new Timeouter(getTimer(), timeout)
+ {
+ @Override
+ protected void handleTimeout(long untouched)
+ {
+ HeartBeatProtocol.this.handleTimeout(untouched);
+ }
+ };
+ }
+ else
+ {
+ timeouter.setTimeout(timeout);
+ timeouter.touch();
+ }
+ }
+
+ @Override
+ protected SignalReactor createSignalReactor(short signalID)
+ {
+ if (signalID == SIGNAL_HEART_BEAT)
+ {
+ return new Indication(HeartBeatProtocol.this, SIGNAL_HEART_BEAT, "HeartBeat") //$NON-NLS-1$
+ {
+ @Override
+ protected void indicating(ExtendedDataInputStream in) throws Exception
+ {
+ checkState(in.readBoolean() == HEART_BEAT, "Invalid heart beat"); //$NON-NLS-1$
+ timeouter.touch();
+ }
+ };
+ }
+
+ return null;
+ }
+
+ protected void handleTimeout(long untouched)
+ {
+ IChannelMultiplexer multiplexer = getChannel().getMultiplexer();
+ LifecycleUtil.deactivate(multiplexer, OMLogger.Level.DEBUG);
+ }
+
+ @Override
+ protected void doDeactivate() throws Exception
+ {
+ if (timeouter != null)
+ {
+ timeouter.dispose();
+ timeouter = null;
+ }
+
+ super.doDeactivate();
+ }
+
+ /**
+ * @since 4.0
+ */
+ protected void requestingStart(ExtendedDataOutputStream out, long rate) throws IOException
+ {
+ out.writeLong(rate);
+ }
+
+ public static Timer getDefaultTimer(IManagedContainer container)
+ {
+ return TimerLifecycle.DaemonFactory.getTimer(container, null);
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static class Server extends SignalProtocol<Object>
+ {
+ private long heartBeatRate;
+
+ private Timer heartBeatTimer;
+
+ private TimerTask heartBeatTimerTask;
+
+ /**
+ * @since 4.0
+ */
+ protected Server(String type)
+ {
+ super(type);
+ }
+
+ public Server()
+ {
+ this(TYPE);
+ }
+
+ public Timer getHeartBeatTimer()
+ {
+ return heartBeatTimer;
+ }
+
+ public void setHeartBeatTimer(Timer heartBeatTimer)
+ {
+ checkInactive();
+ this.heartBeatTimer = heartBeatTimer;
+ }
+
+ @Override
+ protected SignalReactor createSignalReactor(short signalID)
+ {
+ if (signalID == SIGNAL_START)
+ {
+ return new Indication(Server.this, SIGNAL_START, "Start") //$NON-NLS-1$
+ {
+ @Override
+ protected void indicating(ExtendedDataInputStream in) throws Exception
+ {
+ indicatingStart(in);
+ }
+ };
+ }
+
+ return null;
+ }
+
+ @Override
+ protected void doBeforeActivate() throws Exception
+ {
+ super.doBeforeActivate();
+ checkState(heartBeatTimer, "heartBeatTimer"); //$NON-NLS-1$
+ }
+
+ @Override
+ protected void doDeactivate() throws Exception
+ {
+ cancelHeartBeatTask();
+ super.doDeactivate();
+ }
+
+ /**
+ * @since 4.0
+ */
+ protected void indicatingStart(ExtendedDataInputStream in) throws IOException
+ {
+ heartBeatRate = in.readLong();
+ cancelHeartBeatTask();
+ scheduleHeartBeatTask();
+ }
+
+ private void scheduleHeartBeatTask()
+ {
+ heartBeatTimerTask = new TimerTask()
+ {
+ @Override
+ public void run()
+ {
+ try
+ {
+ new Request(Server.this, SIGNAL_HEART_BEAT, "HeartBeat") //$NON-NLS-1$
+ {
+ @Override
+ protected void requesting(ExtendedDataOutputStream out) throws Exception
+ {
+ out.writeBoolean(HEART_BEAT);
+ }
+ }.sendAsync();
+ }
+ catch (Exception ex)
+ {
+ OM.LOG.error("HeartBeatProtocolTask failed", ex);
+ }
+ }
+ };
+
+ heartBeatTimer.schedule(heartBeatTimerTask, 0L, heartBeatRate);
+ }
+
+ private void cancelHeartBeatTask()
+ {
+ if (heartBeatTimerTask != null)
+ {
+ heartBeatTimerTask.cancel();
+ heartBeatTimerTask = null;
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static class Factory extends ServerProtocolFactory
+ {
+ public Factory()
+ {
+ super(TYPE);
+ }
+
+ public Object create(String description) throws ProductCreationException
+ {
+ return new HeartBeatProtocol.Server();
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static class TimerInjector implements IElementProcessor
+ {
+ public TimerInjector()
+ {
+ }
+
+ public Object process(IManagedContainer container, String productGroup, String factoryType, String description,
+ Object element)
+ {
+ if (element instanceof Server)
+ {
+ Server server = (Server)element;
+ if (server.getHeartBeatTimer() == null)
+ {
+ server.setHeartBeatTimer(getTimer(container));
+ }
+ }
+
+ return element;
+ }
+
+ protected Timer getTimer(IManagedContainer container)
+ {
+ return getDefaultTimer(container);
+ }
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/heartbeat/package-info.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/heartbeat/package-info.java
index 2f05a3b690..317b3d6efc 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/heartbeat/package-info.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/heartbeat/package-info.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
+ * 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
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/package-info.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/package-info.java
index da93af610a..3aebcbe561 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/package-info.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/package-info.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
+ * 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
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/wrapping/GZIPStreamWrapperInjector.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/wrapping/GZIPStreamWrapperInjector.java
index eda3aff8c8..cd9757602f 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/wrapping/GZIPStreamWrapperInjector.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/wrapping/GZIPStreamWrapperInjector.java
@@ -1,26 +1,26 @@
-/*
- * 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.signal.wrapping;
-
-import org.eclipse.net4j.util.io.GZIPStreamWrapper;
-
-/**
- * @author Eike Stepper
- */
-public class GZIPStreamWrapperInjector extends StreamWrapperInjector
-{
- public static final GZIPStreamWrapper STREAM_WRAPPER = new GZIPStreamWrapper();
-
- public GZIPStreamWrapperInjector(String protocolID)
- {
- super(protocolID, STREAM_WRAPPER);
- }
-}
+/*
+ * 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.signal.wrapping;
+
+import org.eclipse.net4j.util.io.GZIPStreamWrapper;
+
+/**
+ * @author Eike Stepper
+ */
+public class GZIPStreamWrapperInjector extends StreamWrapperInjector
+{
+ public static final GZIPStreamWrapper STREAM_WRAPPER = new GZIPStreamWrapper();
+
+ public GZIPStreamWrapperInjector(String protocolID)
+ {
+ super(protocolID, STREAM_WRAPPER);
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/wrapping/StreamWrapperInjector.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/wrapping/StreamWrapperInjector.java
index 82b77cdd45..2b08f18829 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/wrapping/StreamWrapperInjector.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/wrapping/StreamWrapperInjector.java
@@ -1,76 +1,76 @@
-/*
- * 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.signal.wrapping;
-
-import org.eclipse.net4j.signal.SignalProtocol;
-import org.eclipse.net4j.util.ObjectUtil;
-import org.eclipse.net4j.util.container.IElementProcessor;
-import org.eclipse.net4j.util.container.IManagedContainer;
-import org.eclipse.net4j.util.io.IStreamWrapper;
-
-/**
- * @author Eike Stepper
- */
-public class StreamWrapperInjector implements IElementProcessor
-{
- private String protocolID;
-
- private IStreamWrapper streamWrapper;
-
- public StreamWrapperInjector(String protocolID, IStreamWrapper streamWrapper)
- {
- this.protocolID = protocolID;
- this.streamWrapper = streamWrapper;
- }
-
- public String getProtocolID()
- {
- return protocolID;
- }
-
- public IStreamWrapper getStreamWrapper()
- {
- return streamWrapper;
- }
-
- public Object process(IManagedContainer container, String productGroup, String factoryType, String description,
- Object element)
- {
- if (element instanceof SignalProtocol<?>)
- {
- SignalProtocol<?> signalProtocol = (SignalProtocol<?>)element;
- if (shouldInject(container, productGroup, factoryType, description, signalProtocol))
- {
- element = inject(container, productGroup, factoryType, description, signalProtocol);
- }
- }
-
- return element;
- }
-
- protected boolean shouldInject(IManagedContainer container, String productGroup, String factoryType,
- String description, SignalProtocol<?> signalProtocol)
- {
- if (signalProtocol.getStreamWrapper() == streamWrapper)
- {
- return false;
- }
-
- return ObjectUtil.equals(signalProtocol.getType(), protocolID);
- }
-
- protected Object inject(IManagedContainer container, String productGroup, String factoryType, String description,
- SignalProtocol<?> signalProtocol)
- {
- signalProtocol.addStreamWrapper(streamWrapper);
- return signalProtocol;
- }
-}
+/*
+ * 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.signal.wrapping;
+
+import org.eclipse.net4j.signal.SignalProtocol;
+import org.eclipse.net4j.util.ObjectUtil;
+import org.eclipse.net4j.util.container.IElementProcessor;
+import org.eclipse.net4j.util.container.IManagedContainer;
+import org.eclipse.net4j.util.io.IStreamWrapper;
+
+/**
+ * @author Eike Stepper
+ */
+public class StreamWrapperInjector implements IElementProcessor
+{
+ private String protocolID;
+
+ private IStreamWrapper streamWrapper;
+
+ public StreamWrapperInjector(String protocolID, IStreamWrapper streamWrapper)
+ {
+ this.protocolID = protocolID;
+ this.streamWrapper = streamWrapper;
+ }
+
+ public String getProtocolID()
+ {
+ return protocolID;
+ }
+
+ public IStreamWrapper getStreamWrapper()
+ {
+ return streamWrapper;
+ }
+
+ public Object process(IManagedContainer container, String productGroup, String factoryType, String description,
+ Object element)
+ {
+ if (element instanceof SignalProtocol<?>)
+ {
+ SignalProtocol<?> signalProtocol = (SignalProtocol<?>)element;
+ if (shouldInject(container, productGroup, factoryType, description, signalProtocol))
+ {
+ element = inject(container, productGroup, factoryType, description, signalProtocol);
+ }
+ }
+
+ return element;
+ }
+
+ protected boolean shouldInject(IManagedContainer container, String productGroup, String factoryType,
+ String description, SignalProtocol<?> signalProtocol)
+ {
+ if (signalProtocol.getStreamWrapper() == streamWrapper)
+ {
+ return false;
+ }
+
+ return ObjectUtil.equals(signalProtocol.getType(), protocolID);
+ }
+
+ protected Object inject(IManagedContainer container, String productGroup, String factoryType, String description,
+ SignalProtocol<?> signalProtocol)
+ {
+ signalProtocol.addStreamWrapper(streamWrapper);
+ return signalProtocol;
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/wrapping/XORStreamWrapperInjector.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/wrapping/XORStreamWrapperInjector.java
index b0f50c33f8..e35b671d74 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/wrapping/XORStreamWrapperInjector.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/wrapping/XORStreamWrapperInjector.java
@@ -1,24 +1,24 @@
-/*
- * 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.signal.wrapping;
-
-import org.eclipse.net4j.util.io.XORStreamWrapper;
-
-/**
- * @author Eike Stepper
- */
-public class XORStreamWrapperInjector extends StreamWrapperInjector
-{
- public XORStreamWrapperInjector(String protocolID, int[] key)
- {
- super(protocolID, new XORStreamWrapper(key));
- }
-}
+/*
+ * 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.signal.wrapping;
+
+import org.eclipse.net4j.util.io.XORStreamWrapper;
+
+/**
+ * @author Eike Stepper
+ */
+public class XORStreamWrapperInjector extends StreamWrapperInjector
+{
+ public XORStreamWrapperInjector(String protocolID, int[] key)
+ {
+ super(protocolID, new XORStreamWrapper(key));
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/wrapping/package-info.java b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/wrapping/package-info.java
index af2eae9589..4f7ce78c8b 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/wrapping/package-info.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/net4j/signal/wrapping/package-info.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
+ * 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
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/Acceptor.java b/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/Acceptor.java
index a61d053df8..ee667662a7 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/Acceptor.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/Acceptor.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
- */
-package org.eclipse.spi.net4j;
-
-import org.eclipse.net4j.ITransportConfig;
-import org.eclipse.net4j.Net4jUtil;
-import org.eclipse.net4j.connector.IConnector;
-import org.eclipse.net4j.util.container.Container;
-import org.eclipse.net4j.util.event.IListener;
-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.log.OMLogger;
-import org.eclipse.net4j.util.om.trace.ContextTracer;
-import org.eclipse.net4j.util.security.INegotiator;
-
-import org.eclipse.internal.net4j.TransportConfig;
-import org.eclipse.internal.net4j.bundle.OM;
-
-import java.util.HashSet;
-import java.util.Set;
-
-/**
- * @author Eike Stepper
- * @since 2.0
- */
-public abstract class Acceptor extends Container<IConnector> implements InternalAcceptor
-{
- private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_ACCEPTOR, Acceptor.class);
-
- private ITransportConfig config;
-
- private transient IListener connectorListener = new LifecycleEventAdapter()
- {
- @Override
- protected void onDeactivated(ILifecycle lifecycle)
- {
- removeConnector((IConnector)lifecycle);
- }
- };
-
- private Set<IConnector> acceptedConnectors = new HashSet<IConnector>(0);
-
- public Acceptor()
- {
- }
-
- public synchronized ITransportConfig getConfig()
- {
- if (config == null)
- {
- config = new TransportConfig(this);
- }
-
- return config;
- }
-
- public synchronized void setConfig(ITransportConfig config)
- {
- this.config = Net4jUtil.copyTransportConfig(this, config);
- }
-
- public INegotiator getNegotiator()
- {
- return getConfig().getNegotiator();
- }
-
- public void setNegotiator(INegotiator negotiator)
- {
- getConfig().setNegotiator(negotiator);
- }
-
- public IConnector[] getAcceptedConnectors()
- {
- synchronized (acceptedConnectors)
- {
- return acceptedConnectors.toArray(new IConnector[acceptedConnectors.size()]);
- }
- }
-
- @Override
- public boolean isEmpty()
- {
- return acceptedConnectors.isEmpty();
- }
-
- public IConnector[] getElements()
- {
- return getAcceptedConnectors();
- }
-
- public void prepareConnector(InternalConnector connector)
- {
- connector.setConfig(getConfig());
- }
-
- public void addConnector(InternalConnector connector)
- {
- synchronized (acceptedConnectors)
- {
- acceptedConnectors.add(connector);
- }
-
- connector.addListener(connectorListener);
- if (TRACER.isEnabled())
- {
- TRACER.trace("Added connector " + connector); //$NON-NLS-1$
- }
-
- fireElementAddedEvent(connector);
- }
-
- public void removeConnector(IConnector connector)
- {
- connector.removeListener(connectorListener);
- synchronized (acceptedConnectors)
- {
- acceptedConnectors.remove(connector);
- }
-
- if (TRACER.isEnabled())
- {
- TRACER.trace("Removed connector " + connector); //$NON-NLS-1$
- }
-
- fireElementRemovedEvent(connector);
- }
-
- public void close()
- {
- LifecycleUtil.deactivate(this, OMLogger.Level.DEBUG);
- }
-
- public boolean isClosed()
- {
- return !isActive();
- }
-
- @Override
- protected void doBeforeActivate() throws Exception
- {
- super.doBeforeActivate();
- if (getConfig().getBufferProvider() == null)
- {
- throw new IllegalStateException("getConfig().getBufferProvider() == null"); //$NON-NLS-1$
- }
- }
-
- @Override
- protected void doDeactivate() throws Exception
- {
- for (IConnector connector : getAcceptedConnectors())
- {
- connector.close();
- }
-
- super.doDeactivate();
- }
-}
+/*
+ * 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.spi.net4j;
+
+import org.eclipse.net4j.ITransportConfig;
+import org.eclipse.net4j.Net4jUtil;
+import org.eclipse.net4j.connector.IConnector;
+import org.eclipse.net4j.util.container.Container;
+import org.eclipse.net4j.util.event.IListener;
+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.log.OMLogger;
+import org.eclipse.net4j.util.om.trace.ContextTracer;
+import org.eclipse.net4j.util.security.INegotiator;
+
+import org.eclipse.internal.net4j.TransportConfig;
+import org.eclipse.internal.net4j.bundle.OM;
+
+import java.util.HashSet;
+import java.util.Set;
+
+/**
+ * @author Eike Stepper
+ * @since 2.0
+ */
+public abstract class Acceptor extends Container<IConnector> implements InternalAcceptor
+{
+ private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_ACCEPTOR, Acceptor.class);
+
+ private ITransportConfig config;
+
+ private transient IListener connectorListener = new LifecycleEventAdapter()
+ {
+ @Override
+ protected void onDeactivated(ILifecycle lifecycle)
+ {
+ removeConnector((IConnector)lifecycle);
+ }
+ };
+
+ private Set<IConnector> acceptedConnectors = new HashSet<IConnector>(0);
+
+ public Acceptor()
+ {
+ }
+
+ public synchronized ITransportConfig getConfig()
+ {
+ if (config == null)
+ {
+ config = new TransportConfig(this);
+ }
+
+ return config;
+ }
+
+ public synchronized void setConfig(ITransportConfig config)
+ {
+ this.config = Net4jUtil.copyTransportConfig(this, config);
+ }
+
+ public INegotiator getNegotiator()
+ {
+ return getConfig().getNegotiator();
+ }
+
+ public void setNegotiator(INegotiator negotiator)
+ {
+ getConfig().setNegotiator(negotiator);
+ }
+
+ public IConnector[] getAcceptedConnectors()
+ {
+ synchronized (acceptedConnectors)
+ {
+ return acceptedConnectors.toArray(new IConnector[acceptedConnectors.size()]);
+ }
+ }
+
+ @Override
+ public boolean isEmpty()
+ {
+ return acceptedConnectors.isEmpty();
+ }
+
+ public IConnector[] getElements()
+ {
+ return getAcceptedConnectors();
+ }
+
+ public void prepareConnector(InternalConnector connector)
+ {
+ connector.setConfig(getConfig());
+ }
+
+ public void addConnector(InternalConnector connector)
+ {
+ synchronized (acceptedConnectors)
+ {
+ acceptedConnectors.add(connector);
+ }
+
+ connector.addListener(connectorListener);
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace("Added connector " + connector); //$NON-NLS-1$
+ }
+
+ fireElementAddedEvent(connector);
+ }
+
+ public void removeConnector(IConnector connector)
+ {
+ connector.removeListener(connectorListener);
+ synchronized (acceptedConnectors)
+ {
+ acceptedConnectors.remove(connector);
+ }
+
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace("Removed connector " + connector); //$NON-NLS-1$
+ }
+
+ fireElementRemovedEvent(connector);
+ }
+
+ public void close()
+ {
+ LifecycleUtil.deactivate(this, OMLogger.Level.DEBUG);
+ }
+
+ public boolean isClosed()
+ {
+ return !isActive();
+ }
+
+ @Override
+ protected void doBeforeActivate() throws Exception
+ {
+ super.doBeforeActivate();
+ if (getConfig().getBufferProvider() == null)
+ {
+ throw new IllegalStateException("getConfig().getBufferProvider() == null"); //$NON-NLS-1$
+ }
+ }
+
+ @Override
+ protected void doDeactivate() throws Exception
+ {
+ for (IConnector connector : getAcceptedConnectors())
+ {
+ connector.close();
+ }
+
+ super.doDeactivate();
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/AcceptorFactory.java b/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/AcceptorFactory.java
index d35ccdf011..69db39c22e 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/AcceptorFactory.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/AcceptorFactory.java
@@ -1,26 +1,26 @@
-/*
- * 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.spi.net4j;
-
-import org.eclipse.net4j.util.factory.Factory;
-
-/**
- * @author Eike Stepper
- */
-public abstract class AcceptorFactory extends Factory
-{
- public static final String PRODUCT_GROUP = "org.eclipse.net4j.acceptors"; //$NON-NLS-1$
-
- public AcceptorFactory(String type)
- {
- super(PRODUCT_GROUP, type);
- }
-}
+/*
+ * 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.spi.net4j;
+
+import org.eclipse.net4j.util.factory.Factory;
+
+/**
+ * @author Eike Stepper
+ */
+public abstract class AcceptorFactory extends Factory
+{
+ public static final String PRODUCT_GROUP = "org.eclipse.net4j.acceptors"; //$NON-NLS-1$
+
+ public AcceptorFactory(String type)
+ {
+ super(PRODUCT_GROUP, type);
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/Channel.java b/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/Channel.java
index 07a37af52d..7dd1c77a4a 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/Channel.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/Channel.java
@@ -1,487 +1,487 @@
-/*
- * 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
- * Andre Dietisheim - maintenance
- */
-package org.eclipse.spi.net4j;
-
-import org.eclipse.net4j.buffer.BufferState;
-import org.eclipse.net4j.buffer.IBuffer;
-import org.eclipse.net4j.buffer.IBufferHandler;
-import org.eclipse.net4j.channel.IChannelMultiplexer;
-import org.eclipse.net4j.protocol.IProtocol;
-import org.eclipse.net4j.util.concurrent.IWorkSerializer;
-import org.eclipse.net4j.util.concurrent.QueueWorkerWorkSerializer;
-import org.eclipse.net4j.util.concurrent.SynchronousWorkSerializer;
-import org.eclipse.net4j.util.event.Event;
-import org.eclipse.net4j.util.event.IListener;
-import org.eclipse.net4j.util.lifecycle.Lifecycle;
-import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
-import org.eclipse.net4j.util.om.log.OMLogger;
-import org.eclipse.net4j.util.om.trace.ContextTracer;
-
-import org.eclipse.internal.net4j.bundle.OM;
-
-import org.eclipse.spi.net4j.InternalChannel.SendQueueEvent.Type;
-
-import java.text.MessageFormat;
-import java.util.Queue;
-import java.util.concurrent.ConcurrentLinkedQueue;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.atomic.AtomicInteger;
-
-/**
- * @author Eike Stepper
- * @since 2.0
- */
-public class Channel extends Lifecycle implements InternalChannel
-{
- private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_CHANNEL, Channel.class);
-
- private String userID;
-
- private InternalChannelMultiplexer channelMultiplexer;
-
- private short id = IBuffer.NO_CHANNEL;
-
- private ExecutorService receiveExecutor;
-
- /**
- * The external handler for buffers passed from the {@link #connector}.
- */
- private IBufferHandler receiveHandler;
-
- private IWorkSerializer receiveSerializer;
-
- private transient Queue<IBuffer> sendQueue;
-
- private transient long sentBuffers;
-
- private transient long receivedBuffers;
-
- public Channel()
- {
- }
-
- public String getUserID()
- {
- return userID;
- }
-
- public void setUserID(String userID)
- {
- this.userID = userID;
- }
-
- public Location getLocation()
- {
- return channelMultiplexer.getLocation();
- }
-
- public boolean isClient()
- {
- return channelMultiplexer.isClient();
- }
-
- public boolean isServer()
- {
- return channelMultiplexer.isServer();
- }
-
- public IChannelMultiplexer getMultiplexer()
- {
- return channelMultiplexer;
- }
-
- public void setMultiplexer(IChannelMultiplexer channelMultiplexer)
- {
- this.channelMultiplexer = (InternalChannelMultiplexer)channelMultiplexer;
- }
-
- public short getID()
- {
- return id;
- }
-
- public void setID(short id)
- {
- checkArg(id != IBuffer.NO_CHANNEL, "id == IBuffer.NO_CHANNEL"); //$NON-NLS-1$
- this.id = id;
- }
-
- public ExecutorService getReceiveExecutor()
- {
- return receiveExecutor;
- }
-
- public void setReceiveExecutor(ExecutorService receiveExecutor)
- {
- this.receiveExecutor = receiveExecutor;
- }
-
- public IBufferHandler getReceiveHandler()
- {
- return receiveHandler;
- }
-
- public void setReceiveHandler(IBufferHandler receiveHandler)
- {
- this.receiveHandler = receiveHandler;
- }
-
- /**
- * @since 3.0
- */
- public long getSentBuffers()
- {
- return sentBuffers;
- }
-
- /**
- * @since 3.0
- */
- public long getReceivedBuffers()
- {
- return receivedBuffers;
- }
-
- public Queue<IBuffer> getSendQueue()
- {
- return sendQueue;
- }
-
- public void sendBuffer(IBuffer buffer)
- {
- handleBuffer(buffer);
- }
-
- /**
- * Handles the given buffer. Ensures it is in the PUTTING state (otherwise ignores it) and sends it on behalf of the
- * send queue.
- *
- * @see IBuffer#getState
- * @see BufferState#PUTTING
- * @see Channel#sendQueue
- */
- public void handleBuffer(IBuffer buffer)
- {
- BufferState state = buffer.getState();
- if (state != BufferState.PUTTING)
- {
- OM.LOG.warn("Ignoring buffer in state == " + state + ": " + this); //$NON-NLS-1$ //$NON-NLS-2$
- return;
- }
-
- if (TRACER.isEnabled())
- {
- TRACER.format("Handling buffer: {0} --> {1}", buffer, this); //$NON-NLS-1$
- }
-
- if (sendQueue == null)
- {
- if (TRACER.isEnabled())
- {
- TRACER.trace("Ignoring buffer because sendQueue == null: " + this); //$NON-NLS-1$
- }
-
- buffer.release();
- }
- else
- {
- sendQueue.add(buffer);
- ++sentBuffers;
- channelMultiplexer.multiplexChannel(this);
- }
- }
-
- /**
- * Handles a buffer sent by the multiplexer. Adds work to the receive queue or releases the buffer.
- *
- * @see InternalChannelMultiplexer#multiplexChannel
- * @see IWorkSerializer
- * @see ReceiverWork
- */
- public void handleBufferFromMultiplexer(IBuffer buffer)
- {
- if (receiveHandler != null)
- {
- if (TRACER.isEnabled())
- {
- TRACER.format("Handling buffer from multiplexer: {0} --> {1}", buffer, this); //$NON-NLS-1$
- }
-
- ++receivedBuffers;
- receiveSerializer.addWork(createReceiverWork(buffer));
- }
- else
- {
- // Shutting down
- buffer.release();
- }
- }
-
- protected ReceiverWork createReceiverWork(IBuffer buffer)
- {
- return new ReceiverWork(buffer);
- }
-
- public short getBufferCapacity()
- {
- return channelMultiplexer.getBufferCapacity();
- }
-
- public IBuffer provideBuffer()
- {
- return channelMultiplexer.provideBuffer();
- }
-
- public void retainBuffer(IBuffer buffer)
- {
- channelMultiplexer.retainBuffer(buffer);
- }
-
- @Override
- public String toString()
- {
- if (receiveHandler instanceof IProtocol)
- {
- IProtocol<?> protocol = (IProtocol<?>)receiveHandler;
- return MessageFormat.format("Channel[{0}, {1}, {2}]", id, getLocation(), protocol.getType()); //$NON-NLS-1$
- }
-
- return MessageFormat.format("Channel[{0}, {1}]", id, getLocation()); //$NON-NLS-1$
- }
-
- @Override
- protected void doBeforeActivate() throws Exception
- {
- super.doBeforeActivate();
- checkState(id != IBuffer.NO_CHANNEL, "channelID == NO_CHANNEL"); //$NON-NLS-1$
- checkState(channelMultiplexer, "channelMultiplexer"); //$NON-NLS-1$
- }
-
- @Override
- protected void doActivate() throws Exception
- {
- super.doActivate();
- sendQueue = new SendQueue();
- if (receiveExecutor == null)
- {
- receiveSerializer = new SynchronousWorkSerializer();
- }
- else
- {
- // CompletionWorkSerializer throws "One command already pending"
- // receiveSerializer = new CompletionWorkSerializer();
- // receiveSerializer = new AsynchronousWorkSerializer(receiveExecutor);
- // receiveSerializer = new SynchronousWorkSerializer();
-
- class ChannelReceiveSerializer extends QueueWorkerWorkSerializer
- {
- @Override
- protected String getThreadName()
- {
- return "ReceiveSerializer-" + Channel.this; //$NON-NLS-1$
- }
- }
-
- receiveSerializer = new ChannelReceiveSerializer();
- }
- }
-
- @Override
- protected void doDeactivate() throws Exception
- {
- unregisterFromMultiplexer();
- if (receiveSerializer != null)
- {
- receiveSerializer.dispose();
- receiveSerializer = null;
- }
-
- if (sendQueue != null)
- {
- sendQueue.clear();
- sendQueue = null;
- }
-
- super.doDeactivate();
- }
-
- protected void unregisterFromMultiplexer()
- {
- channelMultiplexer.closeChannel(this);
- }
-
- public void close()
- {
- LifecycleUtil.deactivate(this, OMLogger.Level.DEBUG);
- }
-
- public boolean isClosed()
- {
- return !isActive();
- }
-
- /**
- * @author Eike Stepper
- */
- protected class ReceiverWork implements Runnable
- {
- private final IBuffer buffer;
-
- /**
- * @since 3.0
- */
- public ReceiverWork(IBuffer buffer)
- {
- this.buffer = buffer;
- }
-
- public void run()
- {
- IBufferHandler receiveHandler = getReceiveHandler();
- if (receiveHandler != null)
- {
- receiveHandler.handleBuffer(buffer);
- }
- else
- {
- // Shutting down
- buffer.release();
- }
- }
- }
-
- /**
- * A queue that holds buffers that shall be sent. This implementation notifies observers of enqueued and dequeued
- * buffers. The notification's deliberately not synchronized. It shall only be used by O&M tooling to offer (not 100%
- * accurate) statistical insights
- *
- * @author Eike Stepper
- * @since 3.0
- */
- protected class SendQueue extends ConcurrentLinkedQueue<IBuffer>
- {
- private static final long serialVersionUID = 1L;
-
- private AtomicInteger size = new AtomicInteger();
-
- protected SendQueue()
- {
- }
-
- @Override
- public boolean add(IBuffer o)
- {
- super.add(o);
- added();
- return true;
- }
-
- @Override
- public boolean offer(IBuffer o)
- {
- super.offer(o);
- added();
- return true;
- }
-
- @Override
- public IBuffer poll()
- {
- IBuffer result = super.poll();
- if (result != null)
- {
- removed();
- }
-
- return result;
- }
-
- @Override
- public IBuffer remove()
- {
- IBuffer result = super.remove();
- if (result != null)
- {
- removed();
- }
-
- return result;
- }
-
- @Override
- public boolean remove(Object o)
- {
- boolean result = super.remove(o);
- if (result)
- {
- removed();
- }
-
- return result;
- }
-
- private void added()
- {
- int queueSize = size.incrementAndGet();
- IListener[] listeners = getListeners();
- if (listeners != null)
- {
- fireEvent(new SendQueueEventImpl(Type.ENQUEUED, queueSize), listeners);
- }
- }
-
- private void removed()
- {
- int queueSize = size.decrementAndGet();
- IListener[] listeners = getListeners();
- if (listeners != null)
- {
- fireEvent(new SendQueueEventImpl(Type.DEQUEUED, queueSize), listeners);
- }
- }
- }
-
- /**
- * @author Eike Stepper
- */
- private final class SendQueueEventImpl extends Event implements SendQueueEvent
- {
- private static final long serialVersionUID = 1L;
-
- private Type type;
-
- private final int queueSize;
-
- private SendQueueEventImpl(Type type, int queueSize)
- {
- super(Channel.this);
- this.type = type;
- this.queueSize = queueSize;
- }
-
- @Override
- public InternalChannel getSource()
- {
- return (InternalChannel)super.getSource();
- }
-
- public Type getType()
- {
- return type;
- }
-
- public int getQueueSize()
- {
- return queueSize;
- }
- }
-}
+/*
+ * 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
+ * Andre Dietisheim - maintenance
+ */
+package org.eclipse.spi.net4j;
+
+import org.eclipse.net4j.buffer.BufferState;
+import org.eclipse.net4j.buffer.IBuffer;
+import org.eclipse.net4j.buffer.IBufferHandler;
+import org.eclipse.net4j.channel.IChannelMultiplexer;
+import org.eclipse.net4j.protocol.IProtocol;
+import org.eclipse.net4j.util.concurrent.IWorkSerializer;
+import org.eclipse.net4j.util.concurrent.QueueWorkerWorkSerializer;
+import org.eclipse.net4j.util.concurrent.SynchronousWorkSerializer;
+import org.eclipse.net4j.util.event.Event;
+import org.eclipse.net4j.util.event.IListener;
+import org.eclipse.net4j.util.lifecycle.Lifecycle;
+import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
+import org.eclipse.net4j.util.om.log.OMLogger;
+import org.eclipse.net4j.util.om.trace.ContextTracer;
+
+import org.eclipse.internal.net4j.bundle.OM;
+
+import org.eclipse.spi.net4j.InternalChannel.SendQueueEvent.Type;
+
+import java.text.MessageFormat;
+import java.util.Queue;
+import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.atomic.AtomicInteger;
+
+/**
+ * @author Eike Stepper
+ * @since 2.0
+ */
+public class Channel extends Lifecycle implements InternalChannel
+{
+ private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_CHANNEL, Channel.class);
+
+ private String userID;
+
+ private InternalChannelMultiplexer channelMultiplexer;
+
+ private short id = IBuffer.NO_CHANNEL;
+
+ private ExecutorService receiveExecutor;
+
+ /**
+ * The external handler for buffers passed from the {@link #connector}.
+ */
+ private IBufferHandler receiveHandler;
+
+ private IWorkSerializer receiveSerializer;
+
+ private transient Queue<IBuffer> sendQueue;
+
+ private transient long sentBuffers;
+
+ private transient long receivedBuffers;
+
+ public Channel()
+ {
+ }
+
+ public String getUserID()
+ {
+ return userID;
+ }
+
+ public void setUserID(String userID)
+ {
+ this.userID = userID;
+ }
+
+ public Location getLocation()
+ {
+ return channelMultiplexer.getLocation();
+ }
+
+ public boolean isClient()
+ {
+ return channelMultiplexer.isClient();
+ }
+
+ public boolean isServer()
+ {
+ return channelMultiplexer.isServer();
+ }
+
+ public IChannelMultiplexer getMultiplexer()
+ {
+ return channelMultiplexer;
+ }
+
+ public void setMultiplexer(IChannelMultiplexer channelMultiplexer)
+ {
+ this.channelMultiplexer = (InternalChannelMultiplexer)channelMultiplexer;
+ }
+
+ public short getID()
+ {
+ return id;
+ }
+
+ public void setID(short id)
+ {
+ checkArg(id != IBuffer.NO_CHANNEL, "id == IBuffer.NO_CHANNEL"); //$NON-NLS-1$
+ this.id = id;
+ }
+
+ public ExecutorService getReceiveExecutor()
+ {
+ return receiveExecutor;
+ }
+
+ public void setReceiveExecutor(ExecutorService receiveExecutor)
+ {
+ this.receiveExecutor = receiveExecutor;
+ }
+
+ public IBufferHandler getReceiveHandler()
+ {
+ return receiveHandler;
+ }
+
+ public void setReceiveHandler(IBufferHandler receiveHandler)
+ {
+ this.receiveHandler = receiveHandler;
+ }
+
+ /**
+ * @since 3.0
+ */
+ public long getSentBuffers()
+ {
+ return sentBuffers;
+ }
+
+ /**
+ * @since 3.0
+ */
+ public long getReceivedBuffers()
+ {
+ return receivedBuffers;
+ }
+
+ public Queue<IBuffer> getSendQueue()
+ {
+ return sendQueue;
+ }
+
+ public void sendBuffer(IBuffer buffer)
+ {
+ handleBuffer(buffer);
+ }
+
+ /**
+ * Handles the given buffer. Ensures it is in the PUTTING state (otherwise ignores it) and sends it on behalf of the
+ * send queue.
+ *
+ * @see IBuffer#getState
+ * @see BufferState#PUTTING
+ * @see Channel#sendQueue
+ */
+ public void handleBuffer(IBuffer buffer)
+ {
+ BufferState state = buffer.getState();
+ if (state != BufferState.PUTTING)
+ {
+ OM.LOG.warn("Ignoring buffer in state == " + state + ": " + this); //$NON-NLS-1$ //$NON-NLS-2$
+ return;
+ }
+
+ if (TRACER.isEnabled())
+ {
+ TRACER.format("Handling buffer: {0} --> {1}", buffer, this); //$NON-NLS-1$
+ }
+
+ if (sendQueue == null)
+ {
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace("Ignoring buffer because sendQueue == null: " + this); //$NON-NLS-1$
+ }
+
+ buffer.release();
+ }
+ else
+ {
+ sendQueue.add(buffer);
+ ++sentBuffers;
+ channelMultiplexer.multiplexChannel(this);
+ }
+ }
+
+ /**
+ * Handles a buffer sent by the multiplexer. Adds work to the receive queue or releases the buffer.
+ *
+ * @see InternalChannelMultiplexer#multiplexChannel
+ * @see IWorkSerializer
+ * @see ReceiverWork
+ */
+ public void handleBufferFromMultiplexer(IBuffer buffer)
+ {
+ if (receiveHandler != null)
+ {
+ if (TRACER.isEnabled())
+ {
+ TRACER.format("Handling buffer from multiplexer: {0} --> {1}", buffer, this); //$NON-NLS-1$
+ }
+
+ ++receivedBuffers;
+ receiveSerializer.addWork(createReceiverWork(buffer));
+ }
+ else
+ {
+ // Shutting down
+ buffer.release();
+ }
+ }
+
+ protected ReceiverWork createReceiverWork(IBuffer buffer)
+ {
+ return new ReceiverWork(buffer);
+ }
+
+ public short getBufferCapacity()
+ {
+ return channelMultiplexer.getBufferCapacity();
+ }
+
+ public IBuffer provideBuffer()
+ {
+ return channelMultiplexer.provideBuffer();
+ }
+
+ public void retainBuffer(IBuffer buffer)
+ {
+ channelMultiplexer.retainBuffer(buffer);
+ }
+
+ @Override
+ public String toString()
+ {
+ if (receiveHandler instanceof IProtocol)
+ {
+ IProtocol<?> protocol = (IProtocol<?>)receiveHandler;
+ return MessageFormat.format("Channel[{0}, {1}, {2}]", id, getLocation(), protocol.getType()); //$NON-NLS-1$
+ }
+
+ return MessageFormat.format("Channel[{0}, {1}]", id, getLocation()); //$NON-NLS-1$
+ }
+
+ @Override
+ protected void doBeforeActivate() throws Exception
+ {
+ super.doBeforeActivate();
+ checkState(id != IBuffer.NO_CHANNEL, "channelID == NO_CHANNEL"); //$NON-NLS-1$
+ checkState(channelMultiplexer, "channelMultiplexer"); //$NON-NLS-1$
+ }
+
+ @Override
+ protected void doActivate() throws Exception
+ {
+ super.doActivate();
+ sendQueue = new SendQueue();
+ if (receiveExecutor == null)
+ {
+ receiveSerializer = new SynchronousWorkSerializer();
+ }
+ else
+ {
+ // CompletionWorkSerializer throws "One command already pending"
+ // receiveSerializer = new CompletionWorkSerializer();
+ // receiveSerializer = new AsynchronousWorkSerializer(receiveExecutor);
+ // receiveSerializer = new SynchronousWorkSerializer();
+
+ class ChannelReceiveSerializer extends QueueWorkerWorkSerializer
+ {
+ @Override
+ protected String getThreadName()
+ {
+ return "ReceiveSerializer-" + Channel.this; //$NON-NLS-1$
+ }
+ }
+
+ receiveSerializer = new ChannelReceiveSerializer();
+ }
+ }
+
+ @Override
+ protected void doDeactivate() throws Exception
+ {
+ unregisterFromMultiplexer();
+ if (receiveSerializer != null)
+ {
+ receiveSerializer.dispose();
+ receiveSerializer = null;
+ }
+
+ if (sendQueue != null)
+ {
+ sendQueue.clear();
+ sendQueue = null;
+ }
+
+ super.doDeactivate();
+ }
+
+ protected void unregisterFromMultiplexer()
+ {
+ channelMultiplexer.closeChannel(this);
+ }
+
+ public void close()
+ {
+ LifecycleUtil.deactivate(this, OMLogger.Level.DEBUG);
+ }
+
+ public boolean isClosed()
+ {
+ return !isActive();
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ protected class ReceiverWork implements Runnable
+ {
+ private final IBuffer buffer;
+
+ /**
+ * @since 3.0
+ */
+ public ReceiverWork(IBuffer buffer)
+ {
+ this.buffer = buffer;
+ }
+
+ public void run()
+ {
+ IBufferHandler receiveHandler = getReceiveHandler();
+ if (receiveHandler != null)
+ {
+ receiveHandler.handleBuffer(buffer);
+ }
+ else
+ {
+ // Shutting down
+ buffer.release();
+ }
+ }
+ }
+
+ /**
+ * A queue that holds buffers that shall be sent. This implementation notifies observers of enqueued and dequeued
+ * buffers. The notification's deliberately not synchronized. It shall only be used by O&M tooling to offer (not 100%
+ * accurate) statistical insights
+ *
+ * @author Eike Stepper
+ * @since 3.0
+ */
+ protected class SendQueue extends ConcurrentLinkedQueue<IBuffer>
+ {
+ private static final long serialVersionUID = 1L;
+
+ private AtomicInteger size = new AtomicInteger();
+
+ protected SendQueue()
+ {
+ }
+
+ @Override
+ public boolean add(IBuffer o)
+ {
+ super.add(o);
+ added();
+ return true;
+ }
+
+ @Override
+ public boolean offer(IBuffer o)
+ {
+ super.offer(o);
+ added();
+ return true;
+ }
+
+ @Override
+ public IBuffer poll()
+ {
+ IBuffer result = super.poll();
+ if (result != null)
+ {
+ removed();
+ }
+
+ return result;
+ }
+
+ @Override
+ public IBuffer remove()
+ {
+ IBuffer result = super.remove();
+ if (result != null)
+ {
+ removed();
+ }
+
+ return result;
+ }
+
+ @Override
+ public boolean remove(Object o)
+ {
+ boolean result = super.remove(o);
+ if (result)
+ {
+ removed();
+ }
+
+ return result;
+ }
+
+ private void added()
+ {
+ int queueSize = size.incrementAndGet();
+ IListener[] listeners = getListeners();
+ if (listeners != null)
+ {
+ fireEvent(new SendQueueEventImpl(Type.ENQUEUED, queueSize), listeners);
+ }
+ }
+
+ private void removed()
+ {
+ int queueSize = size.decrementAndGet();
+ IListener[] listeners = getListeners();
+ if (listeners != null)
+ {
+ fireEvent(new SendQueueEventImpl(Type.DEQUEUED, queueSize), listeners);
+ }
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ private final class SendQueueEventImpl extends Event implements SendQueueEvent
+ {
+ private static final long serialVersionUID = 1L;
+
+ private Type type;
+
+ private final int queueSize;
+
+ private SendQueueEventImpl(Type type, int queueSize)
+ {
+ super(Channel.this);
+ this.type = type;
+ this.queueSize = queueSize;
+ }
+
+ @Override
+ public InternalChannel getSource()
+ {
+ return (InternalChannel)super.getSource();
+ }
+
+ public Type getType()
+ {
+ return type;
+ }
+
+ public int getQueueSize()
+ {
+ return queueSize;
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/ChannelMultiplexer.java b/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/ChannelMultiplexer.java
index 73cfcb1b32..7187174de4 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/ChannelMultiplexer.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/ChannelMultiplexer.java
@@ -1,373 +1,373 @@
-/*
- * 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.spi.net4j;
-
-import org.eclipse.net4j.ITransportConfig;
-import org.eclipse.net4j.Net4jUtil;
-import org.eclipse.net4j.buffer.IBuffer;
-import org.eclipse.net4j.channel.ChannelException;
-import org.eclipse.net4j.channel.IChannel;
-import org.eclipse.net4j.channel.IChannelMultiplexer;
-import org.eclipse.net4j.protocol.IProtocol;
-import org.eclipse.net4j.protocol.IProtocolProvider;
-import org.eclipse.net4j.util.ReflectUtil.ExcludeFromDump;
-import org.eclipse.net4j.util.StringUtil;
-import org.eclipse.net4j.util.concurrent.TimeoutRuntimeException;
-import org.eclipse.net4j.util.container.Container;
-import org.eclipse.net4j.util.factory.FactoryKey;
-import org.eclipse.net4j.util.factory.IFactoryKey;
-import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
-import org.eclipse.net4j.util.om.trace.ContextTracer;
-import org.eclipse.net4j.util.security.INegotiationContext;
-
-import org.eclipse.internal.net4j.TransportConfig;
-import org.eclipse.internal.net4j.bundle.OM;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
-
-/**
- * @author Eike Stepper
- * @since 2.0
- */
-public abstract class ChannelMultiplexer extends Container<IChannel> implements InternalChannelMultiplexer
-{
- private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_CONNECTOR, ChannelMultiplexer.class);
-
- private ITransportConfig config;
-
- private long openChannelTimeout = IChannelMultiplexer.DEFAULT_OPEN_CHANNEL_TIMEOUT;
-
- @ExcludeFromDump
- private transient ConcurrentMap<Short, IChannel> channels = new ConcurrentHashMap<Short, IChannel>();
-
- @ExcludeFromDump
- private transient Set<Short> channelIDs = new HashSet<Short>();
-
- @ExcludeFromDump
- private transient int lastChannelID;
-
- public ChannelMultiplexer()
- {
- }
-
- public synchronized ITransportConfig getConfig()
- {
- if (config == null)
- {
- config = new TransportConfig(this);
- }
-
- return config;
- }
-
- public synchronized void setConfig(ITransportConfig config)
- {
- checkInactive();
- this.config = Net4jUtil.copyTransportConfig(this, config);
- }
-
- public long getOpenChannelTimeout()
- {
- if (openChannelTimeout == IChannelMultiplexer.DEFAULT_OPEN_CHANNEL_TIMEOUT)
- {
- return OM.BUNDLE.getDebugSupport().getDebugOption("open.channel.timeout", 10000); //$NON-NLS-1$
- }
-
- return openChannelTimeout;
- }
-
- public void setOpenChannelTimeout(long openChannelTimeout)
- {
- this.openChannelTimeout = openChannelTimeout;
- }
-
- public final InternalChannel getChannel(short channelID)
- {
- return (InternalChannel)channels.get(channelID);
- }
-
- public final Collection<IChannel> getChannels()
- {
- return channels.values();
- }
-
- @Override
- public boolean isEmpty()
- {
- return channels.isEmpty();
- }
-
- public IChannel[] getElements()
- {
- List<IChannel> list = new ArrayList<IChannel>(getChannels());
- return list.toArray(new IChannel[list.size()]);
- }
-
- public InternalChannel openChannel() throws ChannelException
- {
- return openChannel((IProtocol<?>)null);
- }
-
- public InternalChannel openChannel(String protocolID, Object infraStructure) throws ChannelException
- {
- IProtocol<?> protocol = createProtocol(protocolID, infraStructure);
- if (protocol == null)
- {
- throw new IllegalArgumentException("Unknown protocolID: " + protocolID); //$NON-NLS-1$
- }
-
- return openChannel(protocol);
- }
-
- public InternalChannel openChannel(IProtocol<?> protocol) throws ChannelException
- {
- long start = System.currentTimeMillis();
- doBeforeOpenChannel(protocol);
-
- InternalChannel channel = createChannel();
- initChannel(channel, protocol);
- channel.setID(getNextChannelID());
- addChannel(channel);
-
- try
- {
- try
- {
- long timeout = getOpenChannelTimeout() - System.currentTimeMillis() + start;
- if (timeout <= 0)
- {
- throw new TimeoutRuntimeException();
- }
-
- registerChannelWithPeer(channel.getID(), timeout, protocol);
- }
- catch (TimeoutRuntimeException ex)
- {
- // Adjust the message for the complete timeout time
- String message = "Channel registration timeout after " + getOpenChannelTimeout() + " milliseconds";
- throw new TimeoutRuntimeException(message, ex);
- }
- }
- catch (ChannelException ex)
- {
- throw ex;
- }
- catch (Exception ex)
- {
- throw new ChannelException(ex);
- }
-
- return channel;
- }
-
- public InternalChannel inverseOpenChannel(short channelID, String protocolID)
- {
- IProtocol<?> protocol = createProtocol(protocolID, null);
-
- InternalChannel channel = createChannel();
- initChannel(channel, protocol);
- channel.setID(channelID);
- addChannel(channel);
- return channel;
- }
-
- public void closeChannel(InternalChannel channel) throws ChannelException
- {
- InternalChannel internalChannel = channel;
- deregisterChannelFromPeer(internalChannel);
- removeChannel(internalChannel);
- }
-
- public void inverseCloseChannel(short channelID) throws ChannelException
- {
- InternalChannel channel = getChannel(channelID);
- LifecycleUtil.deactivate(channel);
- }
-
- protected InternalChannel createChannel()
- {
- return new Channel();
- }
-
- protected void initChannel(InternalChannel channel, IProtocol<?> protocol)
- {
- channel.setMultiplexer(this);
- channel.setReceiveExecutor(getConfig().getReceiveExecutor());
- if (protocol != null)
- {
- protocol.setChannel(channel);
- LifecycleUtil.activate(protocol);
- if (TRACER.isEnabled())
- {
- String protocolType = protocol.getType();
- TRACER.format("Opening channel with protocol {0}", protocolType); //$NON-NLS-1$
- }
-
- channel.setReceiveHandler(protocol);
- }
- else
- {
- if (TRACER.isEnabled())
- {
- TRACER.trace("Opening channel without protocol"); //$NON-NLS-1$
- }
- }
- }
-
- @SuppressWarnings("unchecked")
- protected <INFRA_STRUCTURE> IProtocol<INFRA_STRUCTURE> createProtocol(String type, INFRA_STRUCTURE infraStructure)
- {
- if (StringUtil.isEmpty(type))
- {
- return null;
- }
-
- IProtocolProvider protocolProvider = getConfig().getProtocolProvider();
- if (protocolProvider == null)
- {
- throw new ChannelException("No protocol provider configured"); //$NON-NLS-1$
- }
-
- IProtocol<INFRA_STRUCTURE> protocol = (IProtocol<INFRA_STRUCTURE>)protocolProvider.getProtocol(type);
- if (protocol == null)
- {
- throw new ChannelException("Invalid protocol factory: " + type); //$NON-NLS-1$
- }
-
- if (infraStructure != null)
- {
- protocol.setInfraStructure(infraStructure);
- }
-
- return protocol;
- }
-
- protected IFactoryKey createProtocolFactoryKey(String type)
- {
- switch (getLocation())
- {
- case SERVER:
- return new FactoryKey(ServerProtocolFactory.PRODUCT_GROUP, type);
- case CLIENT:
- return new FactoryKey(ClientProtocolFactory.PRODUCT_GROUP, type);
- default:
- throw new IllegalStateException();
- }
- }
-
- protected void doBeforeOpenChannel(IProtocol<?> protocol)
- {
- // Do nothing
- }
-
- @Override
- protected void doDeactivate() throws Exception
- {
- IChannel[] channels;
- synchronized (channelIDs)
- {
- channels = getElements();
- }
-
- for (IChannel channel : channels)
- {
- LifecycleUtil.deactivate(channel);
- }
-
- synchronized (channelIDs)
- {
- this.channels.clear();
- }
-
- super.doDeactivate();
- }
-
- protected abstract INegotiationContext createNegotiationContext();
-
- protected abstract void registerChannelWithPeer(short channelID, long timeout, IProtocol<?> protocol)
- throws ChannelException;
-
- protected abstract void deregisterChannelFromPeer(InternalChannel channel) throws ChannelException;
-
- private short getNextChannelID()
- {
- synchronized (channelIDs)
- {
- int start = lastChannelID;
- int maxValue = Short.MAX_VALUE;
- for (;;)
- {
- ++lastChannelID;
- if (lastChannelID == start)
- {
- throw new ChannelException("Too many channels"); //$NON-NLS-1$
- }
-
- if (lastChannelID > maxValue)
- {
- lastChannelID = 1;
- }
-
- short id = (short)(isClient() ? lastChannelID : -lastChannelID);
- if (channelIDs.add(id))
- {
- return id;
- }
- }
- }
- }
-
- private void addChannel(InternalChannel channel)
- {
- short channelID = channel.getID();
- if (channelID == RESERVED_CHANNEL || channelID == IBuffer.NO_CHANNEL)
- {
- throw new ChannelException("Invalid channel ID: " + channelID); //$NON-NLS-1$
- }
-
- channels.put(channelID, channel);
- LifecycleUtil.activate(channel);
- fireElementAddedEvent(channel);
- }
-
- private void removeChannel(InternalChannel channel)
- {
- try
- {
- short channelID = channel.getID();
- boolean removed;
- synchronized (channelIDs)
- {
- removed = channels.remove(channelID) != null;
- if (removed)
- {
- channelIDs.remove(channelID);
- }
- }
-
- if (removed)
- {
- fireElementRemovedEvent(channel);
- }
- }
- catch (RuntimeException ex)
- {
- OM.LOG.error(ex);
- throw ex;
- }
- }
-}
+/*
+ * 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.spi.net4j;
+
+import org.eclipse.net4j.ITransportConfig;
+import org.eclipse.net4j.Net4jUtil;
+import org.eclipse.net4j.buffer.IBuffer;
+import org.eclipse.net4j.channel.ChannelException;
+import org.eclipse.net4j.channel.IChannel;
+import org.eclipse.net4j.channel.IChannelMultiplexer;
+import org.eclipse.net4j.protocol.IProtocol;
+import org.eclipse.net4j.protocol.IProtocolProvider;
+import org.eclipse.net4j.util.ReflectUtil.ExcludeFromDump;
+import org.eclipse.net4j.util.StringUtil;
+import org.eclipse.net4j.util.concurrent.TimeoutRuntimeException;
+import org.eclipse.net4j.util.container.Container;
+import org.eclipse.net4j.util.factory.FactoryKey;
+import org.eclipse.net4j.util.factory.IFactoryKey;
+import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
+import org.eclipse.net4j.util.om.trace.ContextTracer;
+import org.eclipse.net4j.util.security.INegotiationContext;
+
+import org.eclipse.internal.net4j.TransportConfig;
+import org.eclipse.internal.net4j.bundle.OM;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+/**
+ * @author Eike Stepper
+ * @since 2.0
+ */
+public abstract class ChannelMultiplexer extends Container<IChannel> implements InternalChannelMultiplexer
+{
+ private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_CONNECTOR, ChannelMultiplexer.class);
+
+ private ITransportConfig config;
+
+ private long openChannelTimeout = IChannelMultiplexer.DEFAULT_OPEN_CHANNEL_TIMEOUT;
+
+ @ExcludeFromDump
+ private transient ConcurrentMap<Short, IChannel> channels = new ConcurrentHashMap<Short, IChannel>();
+
+ @ExcludeFromDump
+ private transient Set<Short> channelIDs = new HashSet<Short>();
+
+ @ExcludeFromDump
+ private transient int lastChannelID;
+
+ public ChannelMultiplexer()
+ {
+ }
+
+ public synchronized ITransportConfig getConfig()
+ {
+ if (config == null)
+ {
+ config = new TransportConfig(this);
+ }
+
+ return config;
+ }
+
+ public synchronized void setConfig(ITransportConfig config)
+ {
+ checkInactive();
+ this.config = Net4jUtil.copyTransportConfig(this, config);
+ }
+
+ public long getOpenChannelTimeout()
+ {
+ if (openChannelTimeout == IChannelMultiplexer.DEFAULT_OPEN_CHANNEL_TIMEOUT)
+ {
+ return OM.BUNDLE.getDebugSupport().getDebugOption("open.channel.timeout", 10000); //$NON-NLS-1$
+ }
+
+ return openChannelTimeout;
+ }
+
+ public void setOpenChannelTimeout(long openChannelTimeout)
+ {
+ this.openChannelTimeout = openChannelTimeout;
+ }
+
+ public final InternalChannel getChannel(short channelID)
+ {
+ return (InternalChannel)channels.get(channelID);
+ }
+
+ public final Collection<IChannel> getChannels()
+ {
+ return channels.values();
+ }
+
+ @Override
+ public boolean isEmpty()
+ {
+ return channels.isEmpty();
+ }
+
+ public IChannel[] getElements()
+ {
+ List<IChannel> list = new ArrayList<IChannel>(getChannels());
+ return list.toArray(new IChannel[list.size()]);
+ }
+
+ public InternalChannel openChannel() throws ChannelException
+ {
+ return openChannel((IProtocol<?>)null);
+ }
+
+ public InternalChannel openChannel(String protocolID, Object infraStructure) throws ChannelException
+ {
+ IProtocol<?> protocol = createProtocol(protocolID, infraStructure);
+ if (protocol == null)
+ {
+ throw new IllegalArgumentException("Unknown protocolID: " + protocolID); //$NON-NLS-1$
+ }
+
+ return openChannel(protocol);
+ }
+
+ public InternalChannel openChannel(IProtocol<?> protocol) throws ChannelException
+ {
+ long start = System.currentTimeMillis();
+ doBeforeOpenChannel(protocol);
+
+ InternalChannel channel = createChannel();
+ initChannel(channel, protocol);
+ channel.setID(getNextChannelID());
+ addChannel(channel);
+
+ try
+ {
+ try
+ {
+ long timeout = getOpenChannelTimeout() - System.currentTimeMillis() + start;
+ if (timeout <= 0)
+ {
+ throw new TimeoutRuntimeException();
+ }
+
+ registerChannelWithPeer(channel.getID(), timeout, protocol);
+ }
+ catch (TimeoutRuntimeException ex)
+ {
+ // Adjust the message for the complete timeout time
+ String message = "Channel registration timeout after " + getOpenChannelTimeout() + " milliseconds";
+ throw new TimeoutRuntimeException(message, ex);
+ }
+ }
+ catch (ChannelException ex)
+ {
+ throw ex;
+ }
+ catch (Exception ex)
+ {
+ throw new ChannelException(ex);
+ }
+
+ return channel;
+ }
+
+ public InternalChannel inverseOpenChannel(short channelID, String protocolID)
+ {
+ IProtocol<?> protocol = createProtocol(protocolID, null);
+
+ InternalChannel channel = createChannel();
+ initChannel(channel, protocol);
+ channel.setID(channelID);
+ addChannel(channel);
+ return channel;
+ }
+
+ public void closeChannel(InternalChannel channel) throws ChannelException
+ {
+ InternalChannel internalChannel = channel;
+ deregisterChannelFromPeer(internalChannel);
+ removeChannel(internalChannel);
+ }
+
+ public void inverseCloseChannel(short channelID) throws ChannelException
+ {
+ InternalChannel channel = getChannel(channelID);
+ LifecycleUtil.deactivate(channel);
+ }
+
+ protected InternalChannel createChannel()
+ {
+ return new Channel();
+ }
+
+ protected void initChannel(InternalChannel channel, IProtocol<?> protocol)
+ {
+ channel.setMultiplexer(this);
+ channel.setReceiveExecutor(getConfig().getReceiveExecutor());
+ if (protocol != null)
+ {
+ protocol.setChannel(channel);
+ LifecycleUtil.activate(protocol);
+ if (TRACER.isEnabled())
+ {
+ String protocolType = protocol.getType();
+ TRACER.format("Opening channel with protocol {0}", protocolType); //$NON-NLS-1$
+ }
+
+ channel.setReceiveHandler(protocol);
+ }
+ else
+ {
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace("Opening channel without protocol"); //$NON-NLS-1$
+ }
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ protected <INFRA_STRUCTURE> IProtocol<INFRA_STRUCTURE> createProtocol(String type, INFRA_STRUCTURE infraStructure)
+ {
+ if (StringUtil.isEmpty(type))
+ {
+ return null;
+ }
+
+ IProtocolProvider protocolProvider = getConfig().getProtocolProvider();
+ if (protocolProvider == null)
+ {
+ throw new ChannelException("No protocol provider configured"); //$NON-NLS-1$
+ }
+
+ IProtocol<INFRA_STRUCTURE> protocol = (IProtocol<INFRA_STRUCTURE>)protocolProvider.getProtocol(type);
+ if (protocol == null)
+ {
+ throw new ChannelException("Invalid protocol factory: " + type); //$NON-NLS-1$
+ }
+
+ if (infraStructure != null)
+ {
+ protocol.setInfraStructure(infraStructure);
+ }
+
+ return protocol;
+ }
+
+ protected IFactoryKey createProtocolFactoryKey(String type)
+ {
+ switch (getLocation())
+ {
+ case SERVER:
+ return new FactoryKey(ServerProtocolFactory.PRODUCT_GROUP, type);
+ case CLIENT:
+ return new FactoryKey(ClientProtocolFactory.PRODUCT_GROUP, type);
+ default:
+ throw new IllegalStateException();
+ }
+ }
+
+ protected void doBeforeOpenChannel(IProtocol<?> protocol)
+ {
+ // Do nothing
+ }
+
+ @Override
+ protected void doDeactivate() throws Exception
+ {
+ IChannel[] channels;
+ synchronized (channelIDs)
+ {
+ channels = getElements();
+ }
+
+ for (IChannel channel : channels)
+ {
+ LifecycleUtil.deactivate(channel);
+ }
+
+ synchronized (channelIDs)
+ {
+ this.channels.clear();
+ }
+
+ super.doDeactivate();
+ }
+
+ protected abstract INegotiationContext createNegotiationContext();
+
+ protected abstract void registerChannelWithPeer(short channelID, long timeout, IProtocol<?> protocol)
+ throws ChannelException;
+
+ protected abstract void deregisterChannelFromPeer(InternalChannel channel) throws ChannelException;
+
+ private short getNextChannelID()
+ {
+ synchronized (channelIDs)
+ {
+ int start = lastChannelID;
+ int maxValue = Short.MAX_VALUE;
+ for (;;)
+ {
+ ++lastChannelID;
+ if (lastChannelID == start)
+ {
+ throw new ChannelException("Too many channels"); //$NON-NLS-1$
+ }
+
+ if (lastChannelID > maxValue)
+ {
+ lastChannelID = 1;
+ }
+
+ short id = (short)(isClient() ? lastChannelID : -lastChannelID);
+ if (channelIDs.add(id))
+ {
+ return id;
+ }
+ }
+ }
+ }
+
+ private void addChannel(InternalChannel channel)
+ {
+ short channelID = channel.getID();
+ if (channelID == RESERVED_CHANNEL || channelID == IBuffer.NO_CHANNEL)
+ {
+ throw new ChannelException("Invalid channel ID: " + channelID); //$NON-NLS-1$
+ }
+
+ channels.put(channelID, channel);
+ LifecycleUtil.activate(channel);
+ fireElementAddedEvent(channel);
+ }
+
+ private void removeChannel(InternalChannel channel)
+ {
+ try
+ {
+ short channelID = channel.getID();
+ boolean removed;
+ synchronized (channelIDs)
+ {
+ removed = channels.remove(channelID) != null;
+ if (removed)
+ {
+ channelIDs.remove(channelID);
+ }
+ }
+
+ if (removed)
+ {
+ fireElementRemovedEvent(channel);
+ }
+ }
+ catch (RuntimeException ex)
+ {
+ OM.LOG.error(ex);
+ throw ex;
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/ClientProtocolFactory.java b/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/ClientProtocolFactory.java
index fb20f3acbd..0111ab0cb0 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/ClientProtocolFactory.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/ClientProtocolFactory.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.spi.net4j;
-
-import org.eclipse.net4j.util.factory.Factory;
-
-/**
- * @author Eike Stepper
- * @since 2.0
- */
-public abstract class ClientProtocolFactory extends Factory
-{
- public static final String PRODUCT_GROUP = "org.eclipse.net4j.clientProtocols"; //$NON-NLS-1$
-
- public ClientProtocolFactory(String type)
- {
- super(PRODUCT_GROUP, type);
- }
-}
+/*
+ * 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.spi.net4j;
+
+import org.eclipse.net4j.util.factory.Factory;
+
+/**
+ * @author Eike Stepper
+ * @since 2.0
+ */
+public abstract class ClientProtocolFactory extends Factory
+{
+ public static final String PRODUCT_GROUP = "org.eclipse.net4j.clientProtocols"; //$NON-NLS-1$
+
+ public ClientProtocolFactory(String type)
+ {
+ super(PRODUCT_GROUP, type);
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/Connector.java b/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/Connector.java
index 61cd65a4d0..424e580e2e 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/Connector.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/Connector.java
@@ -1,430 +1,430 @@
-/*
- * 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.spi.net4j;
-
-import org.eclipse.net4j.buffer.IBuffer;
-import org.eclipse.net4j.channel.ChannelException;
-import org.eclipse.net4j.connector.ConnectorException;
-import org.eclipse.net4j.connector.ConnectorState;
-import org.eclipse.net4j.connector.IConnector;
-import org.eclipse.net4j.connector.IConnectorStateEvent;
-import org.eclipse.net4j.protocol.IProtocol;
-import org.eclipse.net4j.util.ReflectUtil.ExcludeFromDump;
-import org.eclipse.net4j.util.event.Event;
-import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
-import org.eclipse.net4j.util.om.log.OMLogger;
-import org.eclipse.net4j.util.om.trace.ContextTracer;
-import org.eclipse.net4j.util.security.INegotiationContext;
-import org.eclipse.net4j.util.security.INegotiator;
-import org.eclipse.net4j.util.security.NegotiationException;
-
-import org.eclipse.internal.net4j.bundle.OM;
-
-import java.text.MessageFormat;
-import java.util.concurrent.CountDownLatch;
-import java.util.concurrent.TimeUnit;
-
-/**
- * @author Eike Stepper
- * @since 2.0
- */
-public abstract class Connector extends ChannelMultiplexer implements InternalConnector
-{
- private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_CONNECTOR, Connector.class);
-
- private String userID;
-
- private transient ConnectorState connectorState = ConnectorState.DISCONNECTED;
-
- @ExcludeFromDump
- private transient CountDownLatch finishedConnecting;
-
- @ExcludeFromDump
- private transient CountDownLatch finishedNegotiating;
-
- @ExcludeFromDump
- private transient INegotiationContext negotiationContext;
-
- @ExcludeFromDump
- private transient NegotiationException negotiationException;
-
- public Connector()
- {
- }
-
- public INegotiator getNegotiator()
- {
- return getConfig().getNegotiator();
- }
-
- public void setNegotiator(INegotiator negotiator)
- {
- getConfig().setNegotiator(negotiator);
- }
-
- public INegotiationContext getNegotiationContext()
- {
- return negotiationContext;
- }
-
- public boolean isClient()
- {
- return getLocation() == Location.CLIENT;
- }
-
- public boolean isServer()
- {
- return getLocation() == Location.SERVER;
- }
-
- public String getUserID()
- {
- return userID;
- }
-
- public void setUserID(String userID)
- {
- checkState(getState() != ConnectorState.CONNECTED, "Connector is already connected"); //$NON-NLS-1$
- if (TRACER.isEnabled())
- {
- TRACER.format("Setting userID {0} for {1}", userID, this); //$NON-NLS-1$
- }
-
- this.userID = userID;
- }
-
- public ConnectorState getState()
- {
- return connectorState;
- }
-
- public void setState(ConnectorState newState) throws ConnectorException
- {
- ConnectorState oldState = getState();
- if (newState != oldState)
- {
- if (TRACER.isEnabled())
- {
- TRACER.format("Setting state {0} (was {1}) for {2}", newState, oldState.toString().toLowerCase(), this); //$NON-NLS-1$
- }
-
- connectorState = newState;
- switch (newState)
- {
- case DISCONNECTED:
- if (finishedConnecting != null)
- {
- finishedConnecting.countDown();
- finishedConnecting = null;
- }
-
- if (finishedNegotiating != null)
- {
- finishedNegotiating.countDown();
- finishedNegotiating = null;
- }
-
- break;
-
- case CONNECTING:
- finishedConnecting = new CountDownLatch(1);
- finishedNegotiating = new CountDownLatch(1);
- // The concrete implementation must advance state to NEGOTIATING or CONNECTED
- break;
-
- case NEGOTIATING:
- finishedConnecting.countDown();
- negotiationContext = createNegotiationContext();
- getNegotiator().negotiate(negotiationContext);
- break;
-
- case CONNECTED:
- negotiationContext = null;
- deferredActivate(true);
- finishedConnecting.countDown();
- finishedNegotiating.countDown();
- break;
- }
-
- fireEvent(new ConnectorStateEvent(this, oldState, newState));
- }
- }
-
- public boolean isDisconnected()
- {
- return connectorState == ConnectorState.DISCONNECTED;
- }
-
- public boolean isConnecting()
- {
- return connectorState == ConnectorState.CONNECTING;
- }
-
- public boolean isNegotiating()
- {
- return connectorState == ConnectorState.NEGOTIATING;
- }
-
- public boolean isConnected()
- {
- if (negotiationException != null)
- {
- throw new ConnectorException("Connector negotiation failed", negotiationException); //$NON-NLS-1$
- }
-
- return connectorState == ConnectorState.CONNECTED;
- }
-
- public void connectAsync() throws ConnectorException
- {
- try
- {
- activate();
- }
- catch (ConnectorException ex)
- {
- throw ex;
- }
- catch (Exception ex)
- {
- throw new ConnectorException(ex);
- }
- }
-
- /**
- * @since 4.0
- */
- public void waitForConnection(long timeout) throws ConnectorException
- {
- String message = "Connection timeout after " + timeout + " milliseconds";
- final long MAX_POLL_INTERVAL = 100L;
- boolean withTimeout = timeout != NO_TIMEOUT;
-
- try
- {
- if (TRACER.isEnabled())
- {
- TRACER.trace("Waiting for connection..."); //$NON-NLS-1$
- }
-
- for (;;)
- {
- long t = MAX_POLL_INTERVAL;
- if (withTimeout)
- {
- t = Math.min(MAX_POLL_INTERVAL, timeout);
- timeout -= MAX_POLL_INTERVAL;
- }
-
- if (t <= 0)
- {
- break;
- }
-
- if (finishedNegotiating == null)
- {
- break;
- }
-
- if (finishedNegotiating.await(t, TimeUnit.MILLISECONDS))
- {
- break;
- }
- }
-
- if (!isConnected())
- {
- throw new ConnectorException(message);
- }
- }
- catch (ConnectorException ex)
- {
- setState(ConnectorState.DISCONNECTED);
- throw ex;
- }
- catch (Exception ex)
- {
- setState(ConnectorState.DISCONNECTED);
- throw new ConnectorException(ex);
- }
- }
-
- /**
- * @since 4.0
- */
- public void connect(long timeout) throws ConnectorException
- {
- connectAsync();
- waitForConnection(timeout);
- }
-
- /**
- * @since 4.0
- */
- public void connect() throws ConnectorException
- {
- connect(NO_TIMEOUT);
- }
-
- public void close()
- {
- LifecycleUtil.deactivate(this, OMLogger.Level.DEBUG);
- }
-
- public boolean isClosed()
- {
- return !isActive();
- }
-
- public short getBufferCapacity()
- {
- return getConfig().getBufferProvider().getBufferCapacity();
- }
-
- public IBuffer provideBuffer()
- {
- return getConfig().getBufferProvider().provideBuffer();
- }
-
- public void retainBuffer(IBuffer buffer)
- {
- getConfig().getBufferProvider().retainBuffer(buffer);
- }
-
- protected void leaveConnecting()
- {
- if (getNegotiator() == null)
- {
- setState(ConnectorState.CONNECTED);
- }
- else
- {
- setState(ConnectorState.NEGOTIATING);
- }
- }
-
- @Override
- protected abstract INegotiationContext createNegotiationContext();
-
- protected NegotiationException getNegotiationException()
- {
- return negotiationException;
- }
-
- protected void setNegotiationException(NegotiationException negotiationException)
- {
- this.negotiationException = negotiationException;
- }
-
- @Override
- protected void initChannel(InternalChannel channel, IProtocol<?> protocol)
- {
- super.initChannel(channel, protocol);
- channel.setUserID(getUserID());
- }
-
- @Override
- protected void deregisterChannelFromPeer(InternalChannel channel) throws ChannelException
- {
- }
-
- public Location getLocation()
- {
- return null;
- }
-
- public String getURL()
- {
- return null;
- }
-
- @Override
- protected boolean isDeferredActivation()
- {
- return true;
- }
-
- @Override
- protected void doBeforeOpenChannel(IProtocol<?> protocol)
- {
- super.doBeforeOpenChannel(protocol);
- long timeout = getOpenChannelTimeout();
- waitForConnection(timeout);
- }
-
- @Override
- protected void doBeforeActivate() throws Exception
- {
- super.doBeforeActivate();
- checkState(getConfig().getBufferProvider(), "getConfig().getBufferProvider()"); //$NON-NLS-1$
-
- if (userID != null && getConfig().getNegotiator() == null)
- {
- throw new IllegalStateException("A user ID on this connector requires a negotiator"); //$NON-NLS-1$
- }
- }
-
- @Override
- protected void doActivate() throws Exception
- {
- super.doActivate();
- setState(ConnectorState.CONNECTING);
- }
-
- @Override
- protected void doDeactivate() throws Exception
- {
- setState(ConnectorState.DISCONNECTED);
- super.doDeactivate();
- }
-
- /**
- * @author Eike Stepper
- */
- private static class ConnectorStateEvent extends Event implements IConnectorStateEvent
- {
- private static final long serialVersionUID = 1L;
-
- private ConnectorState oldState;
-
- private ConnectorState newState;
-
- public ConnectorStateEvent(IConnector source, ConnectorState oldState, ConnectorState newState)
- {
- super(source);
- this.oldState = oldState;
- this.newState = newState;
- }
-
- @Override
- public IConnector getSource()
- {
- return (IConnector)super.getSource();
- }
-
- public ConnectorState getOldState()
- {
- return oldState;
- }
-
- public ConnectorState getNewState()
- {
- return newState;
- }
-
- @Override
- public String toString()
- {
- return MessageFormat.format("ConnectorStateEvent[source={0}, oldState={1}, newState={2}]", getSource(), //$NON-NLS-1$
- getOldState(), getNewState());
- }
- }
-}
+/*
+ * 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.spi.net4j;
+
+import org.eclipse.net4j.buffer.IBuffer;
+import org.eclipse.net4j.channel.ChannelException;
+import org.eclipse.net4j.connector.ConnectorException;
+import org.eclipse.net4j.connector.ConnectorState;
+import org.eclipse.net4j.connector.IConnector;
+import org.eclipse.net4j.connector.IConnectorStateEvent;
+import org.eclipse.net4j.protocol.IProtocol;
+import org.eclipse.net4j.util.ReflectUtil.ExcludeFromDump;
+import org.eclipse.net4j.util.event.Event;
+import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
+import org.eclipse.net4j.util.om.log.OMLogger;
+import org.eclipse.net4j.util.om.trace.ContextTracer;
+import org.eclipse.net4j.util.security.INegotiationContext;
+import org.eclipse.net4j.util.security.INegotiator;
+import org.eclipse.net4j.util.security.NegotiationException;
+
+import org.eclipse.internal.net4j.bundle.OM;
+
+import java.text.MessageFormat;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * @author Eike Stepper
+ * @since 2.0
+ */
+public abstract class Connector extends ChannelMultiplexer implements InternalConnector
+{
+ private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG_CONNECTOR, Connector.class);
+
+ private String userID;
+
+ private transient ConnectorState connectorState = ConnectorState.DISCONNECTED;
+
+ @ExcludeFromDump
+ private transient CountDownLatch finishedConnecting;
+
+ @ExcludeFromDump
+ private transient CountDownLatch finishedNegotiating;
+
+ @ExcludeFromDump
+ private transient INegotiationContext negotiationContext;
+
+ @ExcludeFromDump
+ private transient NegotiationException negotiationException;
+
+ public Connector()
+ {
+ }
+
+ public INegotiator getNegotiator()
+ {
+ return getConfig().getNegotiator();
+ }
+
+ public void setNegotiator(INegotiator negotiator)
+ {
+ getConfig().setNegotiator(negotiator);
+ }
+
+ public INegotiationContext getNegotiationContext()
+ {
+ return negotiationContext;
+ }
+
+ public boolean isClient()
+ {
+ return getLocation() == Location.CLIENT;
+ }
+
+ public boolean isServer()
+ {
+ return getLocation() == Location.SERVER;
+ }
+
+ public String getUserID()
+ {
+ return userID;
+ }
+
+ public void setUserID(String userID)
+ {
+ checkState(getState() != ConnectorState.CONNECTED, "Connector is already connected"); //$NON-NLS-1$
+ if (TRACER.isEnabled())
+ {
+ TRACER.format("Setting userID {0} for {1}", userID, this); //$NON-NLS-1$
+ }
+
+ this.userID = userID;
+ }
+
+ public ConnectorState getState()
+ {
+ return connectorState;
+ }
+
+ public void setState(ConnectorState newState) throws ConnectorException
+ {
+ ConnectorState oldState = getState();
+ if (newState != oldState)
+ {
+ if (TRACER.isEnabled())
+ {
+ TRACER.format("Setting state {0} (was {1}) for {2}", newState, oldState.toString().toLowerCase(), this); //$NON-NLS-1$
+ }
+
+ connectorState = newState;
+ switch (newState)
+ {
+ case DISCONNECTED:
+ if (finishedConnecting != null)
+ {
+ finishedConnecting.countDown();
+ finishedConnecting = null;
+ }
+
+ if (finishedNegotiating != null)
+ {
+ finishedNegotiating.countDown();
+ finishedNegotiating = null;
+ }
+
+ break;
+
+ case CONNECTING:
+ finishedConnecting = new CountDownLatch(1);
+ finishedNegotiating = new CountDownLatch(1);
+ // The concrete implementation must advance state to NEGOTIATING or CONNECTED
+ break;
+
+ case NEGOTIATING:
+ finishedConnecting.countDown();
+ negotiationContext = createNegotiationContext();
+ getNegotiator().negotiate(negotiationContext);
+ break;
+
+ case CONNECTED:
+ negotiationContext = null;
+ deferredActivate(true);
+ finishedConnecting.countDown();
+ finishedNegotiating.countDown();
+ break;
+ }
+
+ fireEvent(new ConnectorStateEvent(this, oldState, newState));
+ }
+ }
+
+ public boolean isDisconnected()
+ {
+ return connectorState == ConnectorState.DISCONNECTED;
+ }
+
+ public boolean isConnecting()
+ {
+ return connectorState == ConnectorState.CONNECTING;
+ }
+
+ public boolean isNegotiating()
+ {
+ return connectorState == ConnectorState.NEGOTIATING;
+ }
+
+ public boolean isConnected()
+ {
+ if (negotiationException != null)
+ {
+ throw new ConnectorException("Connector negotiation failed", negotiationException); //$NON-NLS-1$
+ }
+
+ return connectorState == ConnectorState.CONNECTED;
+ }
+
+ public void connectAsync() throws ConnectorException
+ {
+ try
+ {
+ activate();
+ }
+ catch (ConnectorException ex)
+ {
+ throw ex;
+ }
+ catch (Exception ex)
+ {
+ throw new ConnectorException(ex);
+ }
+ }
+
+ /**
+ * @since 4.0
+ */
+ public void waitForConnection(long timeout) throws ConnectorException
+ {
+ String message = "Connection timeout after " + timeout + " milliseconds";
+ final long MAX_POLL_INTERVAL = 100L;
+ boolean withTimeout = timeout != NO_TIMEOUT;
+
+ try
+ {
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace("Waiting for connection..."); //$NON-NLS-1$
+ }
+
+ for (;;)
+ {
+ long t = MAX_POLL_INTERVAL;
+ if (withTimeout)
+ {
+ t = Math.min(MAX_POLL_INTERVAL, timeout);
+ timeout -= MAX_POLL_INTERVAL;
+ }
+
+ if (t <= 0)
+ {
+ break;
+ }
+
+ if (finishedNegotiating == null)
+ {
+ break;
+ }
+
+ if (finishedNegotiating.await(t, TimeUnit.MILLISECONDS))
+ {
+ break;
+ }
+ }
+
+ if (!isConnected())
+ {
+ throw new ConnectorException(message);
+ }
+ }
+ catch (ConnectorException ex)
+ {
+ setState(ConnectorState.DISCONNECTED);
+ throw ex;
+ }
+ catch (Exception ex)
+ {
+ setState(ConnectorState.DISCONNECTED);
+ throw new ConnectorException(ex);
+ }
+ }
+
+ /**
+ * @since 4.0
+ */
+ public void connect(long timeout) throws ConnectorException
+ {
+ connectAsync();
+ waitForConnection(timeout);
+ }
+
+ /**
+ * @since 4.0
+ */
+ public void connect() throws ConnectorException
+ {
+ connect(NO_TIMEOUT);
+ }
+
+ public void close()
+ {
+ LifecycleUtil.deactivate(this, OMLogger.Level.DEBUG);
+ }
+
+ public boolean isClosed()
+ {
+ return !isActive();
+ }
+
+ public short getBufferCapacity()
+ {
+ return getConfig().getBufferProvider().getBufferCapacity();
+ }
+
+ public IBuffer provideBuffer()
+ {
+ return getConfig().getBufferProvider().provideBuffer();
+ }
+
+ public void retainBuffer(IBuffer buffer)
+ {
+ getConfig().getBufferProvider().retainBuffer(buffer);
+ }
+
+ protected void leaveConnecting()
+ {
+ if (getNegotiator() == null)
+ {
+ setState(ConnectorState.CONNECTED);
+ }
+ else
+ {
+ setState(ConnectorState.NEGOTIATING);
+ }
+ }
+
+ @Override
+ protected abstract INegotiationContext createNegotiationContext();
+
+ protected NegotiationException getNegotiationException()
+ {
+ return negotiationException;
+ }
+
+ protected void setNegotiationException(NegotiationException negotiationException)
+ {
+ this.negotiationException = negotiationException;
+ }
+
+ @Override
+ protected void initChannel(InternalChannel channel, IProtocol<?> protocol)
+ {
+ super.initChannel(channel, protocol);
+ channel.setUserID(getUserID());
+ }
+
+ @Override
+ protected void deregisterChannelFromPeer(InternalChannel channel) throws ChannelException
+ {
+ }
+
+ public Location getLocation()
+ {
+ return null;
+ }
+
+ public String getURL()
+ {
+ return null;
+ }
+
+ @Override
+ protected boolean isDeferredActivation()
+ {
+ return true;
+ }
+
+ @Override
+ protected void doBeforeOpenChannel(IProtocol<?> protocol)
+ {
+ super.doBeforeOpenChannel(protocol);
+ long timeout = getOpenChannelTimeout();
+ waitForConnection(timeout);
+ }
+
+ @Override
+ protected void doBeforeActivate() throws Exception
+ {
+ super.doBeforeActivate();
+ checkState(getConfig().getBufferProvider(), "getConfig().getBufferProvider()"); //$NON-NLS-1$
+
+ if (userID != null && getConfig().getNegotiator() == null)
+ {
+ throw new IllegalStateException("A user ID on this connector requires a negotiator"); //$NON-NLS-1$
+ }
+ }
+
+ @Override
+ protected void doActivate() throws Exception
+ {
+ super.doActivate();
+ setState(ConnectorState.CONNECTING);
+ }
+
+ @Override
+ protected void doDeactivate() throws Exception
+ {
+ setState(ConnectorState.DISCONNECTED);
+ super.doDeactivate();
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ private static class ConnectorStateEvent extends Event implements IConnectorStateEvent
+ {
+ private static final long serialVersionUID = 1L;
+
+ private ConnectorState oldState;
+
+ private ConnectorState newState;
+
+ public ConnectorStateEvent(IConnector source, ConnectorState oldState, ConnectorState newState)
+ {
+ super(source);
+ this.oldState = oldState;
+ this.newState = newState;
+ }
+
+ @Override
+ public IConnector getSource()
+ {
+ return (IConnector)super.getSource();
+ }
+
+ public ConnectorState getOldState()
+ {
+ return oldState;
+ }
+
+ public ConnectorState getNewState()
+ {
+ return newState;
+ }
+
+ @Override
+ public String toString()
+ {
+ return MessageFormat.format("ConnectorStateEvent[source={0}, oldState={1}, newState={2}]", getSource(), //$NON-NLS-1$
+ getOldState(), getNewState());
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/ConnectorFactory.java b/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/ConnectorFactory.java
index 63e0c54f8e..ae16c8861e 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/ConnectorFactory.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/ConnectorFactory.java
@@ -1,26 +1,26 @@
-/*
- * 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.spi.net4j;
-
-import org.eclipse.net4j.util.factory.Factory;
-
-/**
- * @author Eike Stepper
- */
-public abstract class ConnectorFactory extends Factory
-{
- public static final String PRODUCT_GROUP = "org.eclipse.net4j.connectors"; //$NON-NLS-1$
-
- public ConnectorFactory(String type)
- {
- super(PRODUCT_GROUP, type);
- }
-}
+/*
+ * 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.spi.net4j;
+
+import org.eclipse.net4j.util.factory.Factory;
+
+/**
+ * @author Eike Stepper
+ */
+public abstract class ConnectorFactory extends Factory
+{
+ public static final String PRODUCT_GROUP = "org.eclipse.net4j.connectors"; //$NON-NLS-1$
+
+ public ConnectorFactory(String type)
+ {
+ super(PRODUCT_GROUP, type);
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/InternalAcceptor.java b/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/InternalAcceptor.java
index f01912151e..7fec99ef66 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/InternalAcceptor.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/InternalAcceptor.java
@@ -1,22 +1,22 @@
-/*
- * 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.spi.net4j;
-
-import org.eclipse.net4j.ITransportConfigAware;
-import org.eclipse.net4j.acceptor.IAcceptor;
-import org.eclipse.net4j.util.security.INegotiatorAware;
-
-/**
- * @author Eike Stepper
- */
-public interface InternalAcceptor extends IAcceptor, ITransportConfigAware, INegotiatorAware
-{
-}
+/*
+ * 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.spi.net4j;
+
+import org.eclipse.net4j.ITransportConfigAware;
+import org.eclipse.net4j.acceptor.IAcceptor;
+import org.eclipse.net4j.util.security.INegotiatorAware;
+
+/**
+ * @author Eike Stepper
+ */
+public interface InternalAcceptor extends IAcceptor, ITransportConfigAware, INegotiatorAware
+{
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/InternalBuffer.java b/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/InternalBuffer.java
index f11c99dc10..d73b527592 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/InternalBuffer.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/InternalBuffer.java
@@ -1,25 +1,25 @@
-/*
- * 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.spi.net4j;
-
-import org.eclipse.net4j.buffer.IBuffer;
-import org.eclipse.net4j.buffer.IBufferProvider;
-
-/**
- * @author Eike Stepper
- * @noimplement This interface is not intended to be implemented by clients.
- */
-public interface InternalBuffer extends IBuffer
-{
- public void setBufferProvider(IBufferProvider bufferProvider);
-
- public void 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:
+ * Eike Stepper - initial API and implementation
+ */
+package org.eclipse.spi.net4j;
+
+import org.eclipse.net4j.buffer.IBuffer;
+import org.eclipse.net4j.buffer.IBufferProvider;
+
+/**
+ * @author Eike Stepper
+ * @noimplement This interface is not intended to be implemented by clients.
+ */
+public interface InternalBuffer extends IBuffer
+{
+ public void setBufferProvider(IBufferProvider bufferProvider);
+
+ public void dispose();
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/InternalChannel.java b/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/InternalChannel.java
index f1e4e9d34d..3ab8890941 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/InternalChannel.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/InternalChannel.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.spi.net4j;
-
-import org.eclipse.net4j.buffer.IBuffer;
-import org.eclipse.net4j.buffer.IBufferProvider;
-import org.eclipse.net4j.channel.IChannel;
-import org.eclipse.net4j.channel.IChannelMultiplexer;
-import org.eclipse.net4j.util.event.IEvent;
-import org.eclipse.net4j.util.lifecycle.ILifecycle;
-
-import java.util.Queue;
-import java.util.concurrent.ExecutorService;
-
-/**
- * @author Eike Stepper
- */
-public interface InternalChannel extends IChannel, IBufferProvider, ILifecycle
-{
- /**
- * @since 2.0
- */
- public void setID(short id);
-
- /**
- * @since 2.0
- */
- public void setUserID(String userID);
-
- public ExecutorService getReceiveExecutor();
-
- public void setReceiveExecutor(ExecutorService receiveExecutor);
-
- /**
- * @since 2.0
- */
- public void setMultiplexer(IChannelMultiplexer channelMultiplexer);
-
- public void handleBufferFromMultiplexer(IBuffer buffer);
-
- /**
- * @since 3.0
- */
- public long getReceivedBuffers();
-
- /**
- * @since 3.0
- */
- public long getSentBuffers();
-
- public Queue<IBuffer> getSendQueue();
-
- /**
- * An {@link IEvent event} fired from a {@link InternalChannel channel} when a {@link IBuffer buffer} is enqueued or
- * dequeued.
- *
- * @author Eike Stepper
- * @since 3.0
- * @noextend This interface is not intended to be extended by clients.
- * @noimplement This interface is not intended to be implemented by clients.
- */
- public interface SendQueueEvent extends IEvent
- {
- public InternalChannel getSource();
-
- public Type getType();
-
- public int getQueueSize();
-
- /**
- * Enumerates the possible {@link InternalChannel#getSendQueue() send queue} {@link SendQueueEvent event} types.
- *
- * @author Eike Stepper
- */
- public enum Type
- {
- ENQUEUED, DEQUEUED
- }
- }
-}
+/*
+ * 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.spi.net4j;
+
+import org.eclipse.net4j.buffer.IBuffer;
+import org.eclipse.net4j.buffer.IBufferProvider;
+import org.eclipse.net4j.channel.IChannel;
+import org.eclipse.net4j.channel.IChannelMultiplexer;
+import org.eclipse.net4j.util.event.IEvent;
+import org.eclipse.net4j.util.lifecycle.ILifecycle;
+
+import java.util.Queue;
+import java.util.concurrent.ExecutorService;
+
+/**
+ * @author Eike Stepper
+ */
+public interface InternalChannel extends IChannel, IBufferProvider, ILifecycle
+{
+ /**
+ * @since 2.0
+ */
+ public void setID(short id);
+
+ /**
+ * @since 2.0
+ */
+ public void setUserID(String userID);
+
+ public ExecutorService getReceiveExecutor();
+
+ public void setReceiveExecutor(ExecutorService receiveExecutor);
+
+ /**
+ * @since 2.0
+ */
+ public void setMultiplexer(IChannelMultiplexer channelMultiplexer);
+
+ public void handleBufferFromMultiplexer(IBuffer buffer);
+
+ /**
+ * @since 3.0
+ */
+ public long getReceivedBuffers();
+
+ /**
+ * @since 3.0
+ */
+ public long getSentBuffers();
+
+ public Queue<IBuffer> getSendQueue();
+
+ /**
+ * An {@link IEvent event} fired from a {@link InternalChannel channel} when a {@link IBuffer buffer} is enqueued or
+ * dequeued.
+ *
+ * @author Eike Stepper
+ * @since 3.0
+ * @noextend This interface is not intended to be extended by clients.
+ * @noimplement This interface is not intended to be implemented by clients.
+ */
+ public interface SendQueueEvent extends IEvent
+ {
+ public InternalChannel getSource();
+
+ public Type getType();
+
+ public int getQueueSize();
+
+ /**
+ * Enumerates the possible {@link InternalChannel#getSendQueue() send queue} {@link SendQueueEvent event} types.
+ *
+ * @author Eike Stepper
+ */
+ public enum Type
+ {
+ ENQUEUED, DEQUEUED
+ }
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/InternalChannelMultiplexer.java b/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/InternalChannelMultiplexer.java
index 906a361fbf..1dfd554a3c 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/InternalChannelMultiplexer.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/InternalChannelMultiplexer.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.spi.net4j;
-
-import org.eclipse.net4j.ITransportConfigAware;
-import org.eclipse.net4j.buffer.IBufferProvider;
-import org.eclipse.net4j.channel.IChannel;
-import org.eclipse.net4j.channel.IChannelMultiplexer;
-
-/**
- * @author Eike Stepper
- * @since 2.0
- */
-public interface InternalChannelMultiplexer extends IChannelMultiplexer, IBufferProvider, ITransportConfigAware
-{
- /**
- * @since 4.0
- */
- public static final short RESERVED_CHANNEL = 0;
-
- /**
- * Called by an {@link IChannel} each time a new buffer is available for multiplexing. This or another buffer can be
- * dequeued from the outputQueue of the {@link IChannel}.
- */
- public void multiplexChannel(InternalChannel channel);
-
- /**
- * @since 2.0
- */
- public void closeChannel(InternalChannel channel);
-}
+/*
+ * 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.spi.net4j;
+
+import org.eclipse.net4j.ITransportConfigAware;
+import org.eclipse.net4j.buffer.IBufferProvider;
+import org.eclipse.net4j.channel.IChannel;
+import org.eclipse.net4j.channel.IChannelMultiplexer;
+
+/**
+ * @author Eike Stepper
+ * @since 2.0
+ */
+public interface InternalChannelMultiplexer extends IChannelMultiplexer, IBufferProvider, ITransportConfigAware
+{
+ /**
+ * @since 4.0
+ */
+ public static final short RESERVED_CHANNEL = 0;
+
+ /**
+ * Called by an {@link IChannel} each time a new buffer is available for multiplexing. This or another buffer can be
+ * dequeued from the outputQueue of the {@link IChannel}.
+ */
+ public void multiplexChannel(InternalChannel channel);
+
+ /**
+ * @since 2.0
+ */
+ public void closeChannel(InternalChannel channel);
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/InternalConnector.java b/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/InternalConnector.java
index f7002f8934..ec6ac8b6d5 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/InternalConnector.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/InternalConnector.java
@@ -1,21 +1,21 @@
-/*
- * 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.spi.net4j;
-
-import org.eclipse.net4j.connector.IConnector;
-import org.eclipse.net4j.util.security.INegotiatorAware;
-
-/**
- * @author Eike Stepper
- */
-public interface InternalConnector extends IConnector, INegotiatorAware, InternalChannelMultiplexer
-{
-}
+/*
+ * 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.spi.net4j;
+
+import org.eclipse.net4j.connector.IConnector;
+import org.eclipse.net4j.util.security.INegotiatorAware;
+
+/**
+ * @author Eike Stepper
+ */
+public interface InternalConnector extends IConnector, INegotiatorAware, InternalChannelMultiplexer
+{
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/Protocol.java b/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/Protocol.java
index ddba413eb6..a7a5afaf9b 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/Protocol.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/Protocol.java
@@ -1,177 +1,177 @@
-/*
- * 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.spi.net4j;
-
-import org.eclipse.net4j.buffer.IBufferProvider;
-import org.eclipse.net4j.channel.IChannel;
-import org.eclipse.net4j.protocol.IProtocol;
-import org.eclipse.net4j.util.ReflectUtil.ExcludeFromDump;
-import org.eclipse.net4j.util.event.IListener;
-import org.eclipse.net4j.util.lifecycle.ILifecycle;
-import org.eclipse.net4j.util.lifecycle.Lifecycle;
-import org.eclipse.net4j.util.lifecycle.LifecycleEventAdapter;
-import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
-import org.eclipse.net4j.util.om.log.OMLogger;
-
-import java.util.concurrent.ExecutorService;
-
-/**
- * @author Eike Stepper
- * @since 2.0
- */
-public abstract class Protocol<INFRA_STRUCTURE> extends Lifecycle implements IProtocol<INFRA_STRUCTURE>
-{
- private String type;
-
- private ExecutorService executorService;
-
- private IBufferProvider bufferProvider;
-
- private INFRA_STRUCTURE infraStructure;
-
- private IChannel channel;
-
- @ExcludeFromDump
- private transient IListener channelListener = new LifecycleEventAdapter()
- {
- @Override
- protected void onDeactivated(ILifecycle lifecycle)
- {
- handleChannelDeactivation();
- }
- };
-
- private String userID;
-
- public Protocol(String type)
- {
- this.type = type;
- }
-
- public final String getType()
- {
- return type;
- }
-
- public ExecutorService getExecutorService()
- {
- return executorService;
- }
-
- public void setExecutorService(ExecutorService executorService)
- {
- this.executorService = executorService;
- }
-
- public IBufferProvider getBufferProvider()
- {
- return bufferProvider;
- }
-
- public INFRA_STRUCTURE getInfraStructure()
- {
- return infraStructure;
- }
-
- public void setInfraStructure(INFRA_STRUCTURE infraStructure)
- {
- this.infraStructure = infraStructure;
- }
-
- /**
- * @since 2.0
- */
- public Location getLocation()
- {
- return channel.getLocation();
- }
-
- /**
- * @since 2.0
- */
- public boolean isClient()
- {
- return channel.isClient();
- }
-
- /**
- * @since 2.0
- */
- public boolean isServer()
- {
- return channel.isServer();
- }
-
- public IChannel getChannel()
- {
- return channel;
- }
-
- public void setChannel(IChannel newChannel)
- {
- if (channel != newChannel)
- {
- executorService = null;
- bufferProvider = null;
- if (channel != null)
- {
- channel.removeListener(channelListener);
- }
-
- channel = newChannel;
- if (channel != null)
- {
- channel.addListener(channelListener);
- executorService = ((InternalChannel)channel).getReceiveExecutor();
- bufferProvider = (InternalChannel)channel;
- }
- }
- }
-
- public String getUserID()
- {
- if (userID == null && channel != null)
- {
- return channel.getUserID();
- }
-
- return userID;
- }
-
- protected void setUserID(String userID)
- {
- this.userID = userID;
- }
-
- /**
- * @since 2.0
- */
- protected void handleChannelDeactivation()
- {
- LifecycleUtil.deactivate(this, OMLogger.Level.DEBUG);
- }
-
- @Override
- protected void doBeforeActivate() throws Exception
- {
- super.doBeforeActivate();
- checkState(channel, "channel"); //$NON-NLS-1$
- checkState(bufferProvider, "bufferProvider"); //$NON-NLS-1$
- checkState(executorService, "executorService"); //$NON-NLS-1$
- }
-
- @Override
- protected void doDeactivate() throws Exception
- {
- setChannel(null);
- super.doDeactivate();
- }
-}
+/*
+ * 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.spi.net4j;
+
+import org.eclipse.net4j.buffer.IBufferProvider;
+import org.eclipse.net4j.channel.IChannel;
+import org.eclipse.net4j.protocol.IProtocol;
+import org.eclipse.net4j.util.ReflectUtil.ExcludeFromDump;
+import org.eclipse.net4j.util.event.IListener;
+import org.eclipse.net4j.util.lifecycle.ILifecycle;
+import org.eclipse.net4j.util.lifecycle.Lifecycle;
+import org.eclipse.net4j.util.lifecycle.LifecycleEventAdapter;
+import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
+import org.eclipse.net4j.util.om.log.OMLogger;
+
+import java.util.concurrent.ExecutorService;
+
+/**
+ * @author Eike Stepper
+ * @since 2.0
+ */
+public abstract class Protocol<INFRA_STRUCTURE> extends Lifecycle implements IProtocol<INFRA_STRUCTURE>
+{
+ private String type;
+
+ private ExecutorService executorService;
+
+ private IBufferProvider bufferProvider;
+
+ private INFRA_STRUCTURE infraStructure;
+
+ private IChannel channel;
+
+ @ExcludeFromDump
+ private transient IListener channelListener = new LifecycleEventAdapter()
+ {
+ @Override
+ protected void onDeactivated(ILifecycle lifecycle)
+ {
+ handleChannelDeactivation();
+ }
+ };
+
+ private String userID;
+
+ public Protocol(String type)
+ {
+ this.type = type;
+ }
+
+ public final String getType()
+ {
+ return type;
+ }
+
+ public ExecutorService getExecutorService()
+ {
+ return executorService;
+ }
+
+ public void setExecutorService(ExecutorService executorService)
+ {
+ this.executorService = executorService;
+ }
+
+ public IBufferProvider getBufferProvider()
+ {
+ return bufferProvider;
+ }
+
+ public INFRA_STRUCTURE getInfraStructure()
+ {
+ return infraStructure;
+ }
+
+ public void setInfraStructure(INFRA_STRUCTURE infraStructure)
+ {
+ this.infraStructure = infraStructure;
+ }
+
+ /**
+ * @since 2.0
+ */
+ public Location getLocation()
+ {
+ return channel.getLocation();
+ }
+
+ /**
+ * @since 2.0
+ */
+ public boolean isClient()
+ {
+ return channel.isClient();
+ }
+
+ /**
+ * @since 2.0
+ */
+ public boolean isServer()
+ {
+ return channel.isServer();
+ }
+
+ public IChannel getChannel()
+ {
+ return channel;
+ }
+
+ public void setChannel(IChannel newChannel)
+ {
+ if (channel != newChannel)
+ {
+ executorService = null;
+ bufferProvider = null;
+ if (channel != null)
+ {
+ channel.removeListener(channelListener);
+ }
+
+ channel = newChannel;
+ if (channel != null)
+ {
+ channel.addListener(channelListener);
+ executorService = ((InternalChannel)channel).getReceiveExecutor();
+ bufferProvider = (InternalChannel)channel;
+ }
+ }
+ }
+
+ public String getUserID()
+ {
+ if (userID == null && channel != null)
+ {
+ return channel.getUserID();
+ }
+
+ return userID;
+ }
+
+ protected void setUserID(String userID)
+ {
+ this.userID = userID;
+ }
+
+ /**
+ * @since 2.0
+ */
+ protected void handleChannelDeactivation()
+ {
+ LifecycleUtil.deactivate(this, OMLogger.Level.DEBUG);
+ }
+
+ @Override
+ protected void doBeforeActivate() throws Exception
+ {
+ super.doBeforeActivate();
+ checkState(channel, "channel"); //$NON-NLS-1$
+ checkState(bufferProvider, "bufferProvider"); //$NON-NLS-1$
+ checkState(executorService, "executorService"); //$NON-NLS-1$
+ }
+
+ @Override
+ protected void doDeactivate() throws Exception
+ {
+ setChannel(null);
+ super.doDeactivate();
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/ServerProtocolFactory.java b/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/ServerProtocolFactory.java
index 0167d01f1b..a721e9d776 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/ServerProtocolFactory.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/ServerProtocolFactory.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.spi.net4j;
-
-import org.eclipse.net4j.util.factory.Factory;
-
-/**
- * @author Eike Stepper
- * @since 2.0
- */
-public abstract class ServerProtocolFactory extends Factory
-{
- public static final String PRODUCT_GROUP = "org.eclipse.net4j.serverProtocols"; //$NON-NLS-1$
-
- public ServerProtocolFactory(String type)
- {
- super(PRODUCT_GROUP, type);
- }
-}
+/*
+ * 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.spi.net4j;
+
+import org.eclipse.net4j.util.factory.Factory;
+
+/**
+ * @author Eike Stepper
+ * @since 2.0
+ */
+public abstract class ServerProtocolFactory extends Factory
+{
+ public static final String PRODUCT_GROUP = "org.eclipse.net4j.serverProtocols"; //$NON-NLS-1$
+
+ public ServerProtocolFactory(String type)
+ {
+ super(PRODUCT_GROUP, type);
+ }
+}
diff --git a/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/package-info.java b/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/package-info.java
index 2783b778da..15a3a41f9e 100644
--- a/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/package-info.java
+++ b/plugins/org.eclipse.net4j/src/org/eclipse/spi/net4j/package-info.java
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2004 - 2011 Eike Stepper (Berlin, Germany) and others.
+ * 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

Back to the top