Adding Federation Support
The Next Naming System
Once you have done the processing for the current naming system, as described in the previous section, very little work is left to be done to complete the operation.Here is a sample implementation of bind() from the previous section.
Evaluating the code with the try clause can result in any of three outcomes.public void bind(Name name, Object bindObj) throws NamingException { try { Name[] nm = parseComponents(name); Name mine = nm[0]; Name rest = nm[1]; if (rest == null || rest.isEmpty()) { // Terminal; just use head bind_internal(mine, bindObj); } else if (rest.get(0).equals("") && rest.size() == 1) { // Terminal nns bind_nns(mine, bindObj); } else if (mine.isEmpty() || isAllEmpty(rest)) { // Intermediate; resolve current components as intermediate Object obj = lookup_nns(mine); // Skip the leading forward slash throw fillInCPE(obj, mine, rest.getSuffix(1)); } else { // Intermediate; resolve current components as intermediate Object obj = resolveIntermediate_nns(mine, rest); throw fillInCPE(obj, mine, rest); } } catch (CannotProceedException e) { Context cctx = NamingManager.getContinuationContext(e); cctx.bind(e.getRemainingName(), bindObj); } }You handle the last outcome by attempting to find a continuation context, by using NamingManager.getContinuationContext() or DirectoryManager.getContinuationDirContext(), based on information in the CannotProceedException. You then proceed to invoke the same method on the continuation context by using the remaining name.
- The operation completes successfully.
- The operation results in an error and throws a NamingException.
- The operation needs to be continued in the nns and throws a CannotProceedException
The approach described here is based heavily on throwing and catching a CannotProceedException. However, it is not the only approach. You could achieve the same results by using an iterative approach.
Adding Federation Support