/*
 *
 *  Licensed to the Apache Software Foundation (ASF) under one or more
 *  contributor license agreements.  See the NOTICE file distributed with
 *  this work for additional information regarding copyright ownership.
 *  The ASF licenses this file to You under the Apache License, Version 2.0
 *  (the "License"); you may not use this file except in compliance with
 *  the License.  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 */

package org.apache.royale.amfsamples;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;

import flex.messaging.MessageBroker;
import flex.messaging.config.ConfigMap;
import flex.messaging.services.ServiceAdapter;
import flex.messaging.services.remoting.RemotingDestination;

@SpringBootApplication
@ServletComponentScan("org.apache.royale.amfsamples")
public class BlazeDSSpringBootApplication {

    public static void main(String[] args) {

        //BlazeDS normal application setup
        SpringApplication application = new SpringApplication(BlazeDSSpringBootApplication.class);
        application.run(args);

        // makes "compressedService" uses "compressed-java-object" adapter that performs compression on AMF data
        // this can be done usgin spring xml with <flex:remoting-service default-adapter-id="the-compression-adapter"/>
        MessageBroker messageBroker = MessageBroker.getMessageBroker("_messageBroker");
        RemotingDestination destination = RemotingDestination.getRemotingDestination("_messageBroker", "compressedService");

        ConfigMap serviceAdapterConfig = new ConfigMap();
        serviceAdapterConfig.addProperty("include-packages", "org.apache.royale.");

        ServiceAdapter serviceAdapter = destination.createAdapter("compressed-java-object");
        serviceAdapter.initialize("compressed-java-object", serviceAdapterConfig);

        destination.setAdapter(serviceAdapter);
    }
}
