001
014
015 package com.liferay.portal.kernel.nio.intraband;
016
017 import com.liferay.portal.kernel.nio.intraband.blocking.ExecutorIntraband;
018 import com.liferay.portal.kernel.nio.intraband.nonblocking.SelectorIntraband;
019 import com.liferay.portal.kernel.nio.intraband.welder.Welder;
020 import com.liferay.portal.kernel.nio.intraband.welder.WelderFactoryUtil;
021 import com.liferay.portal.kernel.nio.intraband.welder.socket.SocketWelder;
022 import com.liferay.portal.kernel.util.GetterUtil;
023 import com.liferay.portal.kernel.util.PropsKeys;
024 import com.liferay.portal.kernel.util.Validator;
025
026 import java.io.IOException;
027
028 import java.lang.reflect.Constructor;
029
030
033 public class IntrabandFactoryUtil {
034
035 public static Intraband createIntraband() throws IOException {
036 if (Validator.isNotNull(_INTRABAND_IMPL)) {
037 try {
038 Class<? extends Intraband> intrabandClass =
039 (Class<? extends Intraband>)Class.forName(_INTRABAND_IMPL);
040
041 Constructor<? extends Intraband> constructor =
042 intrabandClass.getConstructor(long.class);
043
044 return constructor.newInstance(_INTRABAND_TIMEOUT_DEFAULT);
045 }
046 catch (Exception e) {
047 throw new RuntimeException(
048 "Unable to instantiate " + _INTRABAND_IMPL, e);
049 }
050 }
051 else {
052 Class<? extends Welder> welderClass =
053 WelderFactoryUtil.getWelderClass();
054
055 if (welderClass.equals(SocketWelder.class)) {
056 return new SelectorIntraband(_INTRABAND_TIMEOUT_DEFAULT);
057 }
058 else {
059 return new ExecutorIntraband(_INTRABAND_TIMEOUT_DEFAULT);
060 }
061 }
062 }
063
064 private static final String _INTRABAND_IMPL = GetterUtil.getString(
065 System.getProperty(PropsKeys.INTRABAND_IMPL));
066
067 private static final long _INTRABAND_TIMEOUT_DEFAULT = GetterUtil.getLong(
068 System.getProperty(PropsKeys.INTRABAND_TIMEOUT_DEFAULT));
069
070 }