1 20 package org.apache.mina.common.support; 21 22 import java.lang.reflect.Method ; 23 24 import org.apache.mina.common.DefaultIoFilterChainBuilder; 25 import org.apache.mina.common.ExecutorThreadModel; 26 import org.apache.mina.common.IoFilterChainBuilder; 27 import org.apache.mina.common.IoServiceConfig; 28 import org.apache.mina.common.ThreadModel; 29 30 36 public abstract class BaseIoServiceConfig implements IoServiceConfig, Cloneable { 37 40 private IoFilterChainBuilder filterChainBuilder = new DefaultIoFilterChainBuilder(); 41 42 45 private final ThreadModel defaultThreadModel = ExecutorThreadModel 46 .getInstance("AnonymousIoService"); 47 48 51 private ThreadModel threadModel = defaultThreadModel; 52 53 public BaseIoServiceConfig() { 54 super(); 55 } 56 57 public IoFilterChainBuilder getFilterChainBuilder() { 58 return filterChainBuilder; 59 } 60 61 public void setFilterChainBuilder(IoFilterChainBuilder builder) { 62 if (builder == null) { 63 builder = new DefaultIoFilterChainBuilder(); 64 } 65 filterChainBuilder = builder; 66 } 67 68 public DefaultIoFilterChainBuilder getFilterChain() { 69 if (filterChainBuilder instanceof DefaultIoFilterChainBuilder) { 70 return (DefaultIoFilterChainBuilder) filterChainBuilder; 71 } else { 72 throw new IllegalStateException ( 73 "Current filter chain builder is not a DefaultIoFilterChainBuilder."); 74 } 75 } 76 77 public ThreadModel getThreadModel() { 78 return threadModel; 79 } 80 81 public void setThreadModel(ThreadModel threadModel) { 82 if (threadModel == null) { 83 threadModel = defaultThreadModel; 86 } 87 this.threadModel = threadModel; 88 } 89 90 @Override 91 public Object clone() { 92 BaseIoServiceConfig ret; 93 try { 94 ret = (BaseIoServiceConfig) super.clone(); 95 } catch (CloneNotSupportedException e) { 96 throw (InternalError ) new InternalError ().initCause(e); 97 } 98 99 try { 101 Method cloneMethod = this.filterChainBuilder.getClass().getMethod( 102 "clone"); 103 if (cloneMethod.isAccessible()) { 104 ret.filterChainBuilder = (IoFilterChainBuilder) cloneMethod 105 .invoke(this.filterChainBuilder); 106 } 107 } catch (Exception e) { 108 } 110 111 return ret; 112 } 113 } 114 | Popular Tags |