@Bean public HazelcastInstance hazelcastInstance() { MapAttributeConfig attributeConfig = new MapAttributeConfig() .setName(HazelcastSessionRepository.PRINCIPAL_NAME_ATTRIBUTE) .setExtractor(PrincipalNameExtractor.class.getName()); Config config = new Config(); config.getMapConfig(HazelcastSessionRepository.DEFAULT_SESSION_MAP_NAME) // <2> .addMapAttributeConfig(attributeConfig) .addMapIndexConfig(new MapIndexConfig( HazelcastSessionRepository.PRINCIPAL_NAME_ATTRIBUTE, false)); return Hazelcast.newHazelcastInstance(config); // <3> }
public MapAttributeConfig(MapAttributeConfig config) { name = config.getName(); extractor = config.getExtractor(); }
/** * Creates a MapAttributeConfig with the given attribute and ordered setting. * <p> * Name may begin with an ascii letter [A-Za-z] or digit [0-9] and may contain ascii letters [A-Za-z], digits [0-9] * or underscores later on. * * @param name the name given to an attribute that is going to be extracted * @param extractor full class name of the extractor used to extract the value of the attribute * @see #setName(String) * @see #setExtractor(String) */ public MapAttributeConfig(String name, String extractor) { setName(name); setExtractor(extractor); }
@Override public IdentifiedDataSerializable createNew(Integer arg) { return new MapAttributeConfig(); } };
private static ValueExtractor instantiateExtractorWithClassForName(MapAttributeConfig config) { try { Class<?> clazz = Class.forName(config.getExtractor()); Object extractor = clazz.newInstance(); if (extractor instanceof ValueExtractor) { return (ValueExtractor) extractor; } else { throw new IllegalArgumentException("Extractor does not extend ValueExtractor class " + config); } } catch (IllegalAccessException ex) { throw new IllegalArgumentException("Could not initialize extractor " + config, ex); } catch (InstantiationException ex) { throw new IllegalArgumentException("Could not initialize extractor " + config, ex); } catch (ClassNotFoundException ex) { throw new IllegalArgumentException("Could not initialize extractor " + config, ex); } }
private static String checkName(String name) { checkHasText(name, "Map attribute name must contain text"); checkNameValid(name); checkNotQueryConstant(name); return name; }
static Map<String, ValueExtractor> instantiateExtractors(List<MapAttributeConfig> mapAttributeConfigs, ClassLoader classLoader) { Map<String, ValueExtractor> extractors = createHashMap(mapAttributeConfigs.size()); for (MapAttributeConfig config : mapAttributeConfigs) { if (extractors.containsKey(config.getName())) { throw new IllegalArgumentException("Could not add " + config + ". Extractor for this attribute name already added."); } extractors.put(config.getName(), instantiateExtractor(config, classLoader)); } return extractors; }
/** * Sets the name of the attribute extracted by the extractor. * The name cannot be equal to any of the query constants. * * @param name the name of the attribute extracted by the extractor * @return the updated MapAttributeConfig * @throws IllegalArgumentException if attribute is null,an empty or inappropriate string * @see QueryConstants */ public MapAttributeConfig setName(String name) { this.name = checkName(name); return this; }
public MapAttributeConfig(MapAttributeConfig config) { name = config.getName(); extractor = config.getExtractor(); }
/** * Creates a MapAttributeConfig with the given attribute and ordered setting. * <p> * Name may begin with an ascii letter [A-Za-z] or digit [0-9] and may contain ascii letters [A-Za-z], digits [0-9] * or underscores later on. * * @param name the name given to an attribute that is going to be extracted * @param extractor full class name of the extractor used to extract the value of the attribute * @see #setName(String) * @see #setExtractor(String) */ public MapAttributeConfig(String name, String extractor) { setName(name); setExtractor(extractor); }
@Override public IdentifiedDataSerializable createNew(Integer arg) { return new MapAttributeConfig(); } };
private static ValueExtractor instantiateExtractorWithConfigClassLoader(MapAttributeConfig config, ClassLoader classLoader) { try { Class<?> clazz = classLoader.loadClass(config.getExtractor()); Object extractor = clazz.newInstance(); if (extractor instanceof ValueExtractor) { return (ValueExtractor) extractor; } else { throw new IllegalArgumentException("Extractor does not extend ValueExtractor class " + config); } } catch (IllegalAccessException ex) { throw new IllegalArgumentException("Could not initialize extractor " + config, ex); } catch (InstantiationException ex) { throw new IllegalArgumentException("Could not initialize extractor " + config, ex); } catch (ClassNotFoundException ex) { throw new IllegalArgumentException("Could not initialize extractor " + config, ex); } }
private static String checkName(String name) { checkHasText(name, "Map attribute name must contain text"); checkNameValid(name); checkNotQueryConstant(name); return name; }
static Map<String, ValueExtractor> instantiateExtractors(List<MapAttributeConfig> mapAttributeConfigs, ClassLoader classLoader) { Map<String, ValueExtractor> extractors = createHashMap(mapAttributeConfigs.size()); for (MapAttributeConfig config : mapAttributeConfigs) { if (extractors.containsKey(config.getName())) { throw new IllegalArgumentException("Could not add " + config + ". Extractor for this attribute name already added."); } extractors.put(config.getName(), instantiateExtractor(config, classLoader)); } return extractors; }
/** * Sets the name of the attribute extracted by the extractor. * The name cannot be equal to any of the query constants. * * @param name the name of the attribute extracted by the extractor * @return the updated MapAttributeConfig * @throws IllegalArgumentException if attribute is null,an empty or inappropriate string * @see QueryConstants */ public MapAttributeConfig setName(String name) { this.name = checkName(name); return this; }
public static MapAttributeConfig decode(ClientMessage clientMessage) { MapAttributeConfig config = new MapAttributeConfig(); config.setName(clientMessage.getStringUtf8()); config.setExtractor(clientMessage.getStringUtf8()); return config; }
public static int calculateDataSize(MapAttributeConfig config) { int dataSize = ParameterUtil.calculateDataSize(config.getName()); dataSize += ParameterUtil.calculateDataSize(config.getExtractor()); return dataSize; } }
private void mapAttributesHandle(Node n, MapConfig mapConfig) { for (Node extractorNode : childElements(n)) { if ("attribute".equals(cleanNodeName(extractorNode))) { NamedNodeMap attrs = extractorNode.getAttributes(); String extractor = getTextContent(attrs.getNamedItem("extractor")); String name = getTextContent(extractorNode); mapConfig.addMapAttributeConfig(new MapAttributeConfig(name, extractor)); } } }
private static ValueExtractor instantiateExtractorWithClassForName(MapAttributeConfig config) { try { Class<?> clazz = Class.forName(config.getExtractor()); Object extractor = clazz.newInstance(); if (extractor instanceof ValueExtractor) { return (ValueExtractor) extractor; } else { throw new IllegalArgumentException("Extractor does not extend ValueExtractor class " + config); } } catch (IllegalAccessException ex) { throw new IllegalArgumentException("Could not initialize extractor " + config, ex); } catch (InstantiationException ex) { throw new IllegalArgumentException("Could not initialize extractor " + config, ex); } catch (ClassNotFoundException ex) { throw new IllegalArgumentException("Could not initialize extractor " + config, ex); } }
public static MapAttributeConfig decode(ClientMessage clientMessage) { MapAttributeConfig config = new MapAttributeConfig(); config.setName(clientMessage.getStringUtf8()); config.setExtractor(clientMessage.getStringUtf8()); return config; }