001    /*
002    @license.text@  
003     */
004    package biz.hammurapi.metrics;
005    
006    import java.rmi.Naming;
007    import java.rmi.RemoteException;
008    
009    import biz.hammurapi.config.Component;
010    import biz.hammurapi.config.ConfigurationException;
011    import biz.hammurapi.config.DomConfigurable;
012    import biz.hammurapi.xml.dom.AbstractDomObject;
013    
014    
015    /**
016     * @author Pavel Vlasov
017     */
018    public class RemoteSlicingMeasurementCategoryFactory extends SlicingMeasurementCategoryFactory implements DomConfigurable, Component {    
019            private RemoteSliceConsumer remoteSliceConsumer;
020        
021            /**
022             * @param remoteConsumer
023             */
024            public RemoteSlicingMeasurementCategoryFactory(RemoteSliceConsumer remoteConsumer) {
025                    super();
026                    this.remoteSliceConsumer = remoteConsumer;
027            }
028            
029            public RemoteSlicingMeasurementCategoryFactory() {
030                    
031            }
032            
033            protected SliceConsumer createSliceConsumer() throws ConfigurationException {
034                    try {
035                    if (remoteSliceConsumer==null) {
036                            remoteSliceConsumer=(RemoteSliceConsumer) Naming.lookup(AbstractDomObject.getElementText(configElement, "remote-slice-consumer"));
037                    }
038                    
039                            return new SliceConsumer() {
040                                    
041                                    String rootCategory=AbstractDomObject.getElementText(configElement, "root-category");
042            
043                                    public boolean consumeSlice(String category, Slice slice) {
044                                            try {
045                                                    return remoteSliceConsumer.consumeSlice(rootCategory+"."+category, slice);
046                                            } catch (RemoteException e) {
047                                                    e.printStackTrace();
048                                                    return false;
049                                            }
050                                    }
051                                    
052                            };
053                    } catch (Exception e) {
054                            throw new ConfigurationException(e);
055                    }
056            }
057    }