package org.openehealth.ipf.platform.camel.ihe.mllp.core;

import lombok.experimental.Delegate;
import org.apache.camel.component.mina2.Mina2Consumer;
import org.apache.camel.impl.DefaultConsumer;
import org.apache.mina.core.service.IoAcceptor;

/**
 * MllpConsumer wraps a Mina2Consumer for having a hook to shutdown some Mina
 * resources when the consumer is closing
 */
public class MllpConsumer extends DefaultConsumer {

    // The reason for this interface is to convince the Delegate annotation to *not* delegate
    // the stop method. Weird API, really.
    private interface DoStop {
        @SuppressWarnings("unused")
        void stop() throws Exception;
    }

    @Delegate(excludes=DoStop.class)
    private final Mina2Consumer consumer;

    MllpConsumer(Mina2Consumer consumer) {
        // Everything will be delegated
        super(consumer.getEndpoint(), consumer.getProcessor());
        this.consumer = consumer;
    }

    /**
     * After stopping the consumer, stop the Mina acceptor, too
     * @throws Exception
     */
    @Override
    public void stop() throws Exception {
        super.stop();
        // Delegates call to Mina2Consumer
        IoAcceptor ioAcceptor = getAcceptor();
        if (ioAcceptor != null) {
            ioAcceptor.dispose(true);
        }
    }
}

@@ -1,8 +1,623 @@
+/*%0A * Copyright 2015 the original author or authors.%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *     http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0A
 package 
@@ -1306,17 +1306,19 @@
 excludes
-=
+ = 
 DoStop.c

add copyright