
com.generallycloud.nio.container.protobase.startup.ProtobaseServerLoadStartup Maven / Gradle / Ivy
/*
* Copyright 2015 GenerallyCloud.com
*
* Licensed 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 com.generallycloud.nio.container.protobase.startup;
import com.generallycloud.nio.acceptor.SocketChannelAcceptor;
import com.generallycloud.nio.codec.protobase.ProtobaseProtocolFactory;
import com.generallycloud.nio.codec.protobase.future.ProtobaseReadFuture;
import com.generallycloud.nio.common.SharedBundle;
import com.generallycloud.nio.component.SocketChannelContext;
import com.generallycloud.nio.component.SocketChannelContextImpl;
import com.generallycloud.nio.component.IoEventHandleAdaptor;
import com.generallycloud.nio.component.LoggerSocketSEListener;
import com.generallycloud.nio.component.SocketSession;
import com.generallycloud.nio.configuration.PropertiesSCLoader;
import com.generallycloud.nio.configuration.ServerConfiguration;
import com.generallycloud.nio.protocol.ReadFuture;
public class ProtobaseServerLoadStartup {
public static void main(String[] args) throws Exception {
SharedBundle.instance().loadAllProperties("nio");
IoEventHandleAdaptor eventHandleAdaptor = new IoEventHandleAdaptor() {
@Override
public void accept(SocketSession session, ReadFuture future) throws Exception {
ProtobaseReadFuture f = (ProtobaseReadFuture)future;
f.write("yes server already accept your message");
f.write(f.getReadText());
session.flush(future);
}
};
PropertiesSCLoader loader = new PropertiesSCLoader();
ServerConfiguration configuration = loader.loadConfiguration(SharedBundle.instance());
SocketChannelContext context = new SocketChannelContextImpl(configuration);
SocketChannelAcceptor acceptor = new SocketChannelAcceptor(context);
try {
context.setIoEventHandleAdaptor(eventHandleAdaptor);
context.addSessionEventListener(new LoggerSocketSEListener());
acceptor.getContext().setProtocolFactory(new ProtobaseProtocolFactory());
acceptor.bind();
} catch (Throwable e) {
acceptor.unbind();
throw new RuntimeException(e);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy