Skip to content

Channelfinder-based name server for Channel Access? #2

@kasemir

Description

@kasemir

Looked at the CA server support that's included in CAJ. It's very easy to create the start of a "caSnooper" that logs all searches, but didn't find an obvious way to act as a name server, see comments in example:

import java.net.InetSocketAddress;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.Logger;
import gov.aps.jca.CAException;
import gov.aps.jca.CAStatus;
import gov.aps.jca.CAStatusException;
import gov.aps.jca.JCALibrary;
import gov.aps.jca.cas.ProcessVariable;
import gov.aps.jca.cas.ProcessVariableAttachCallback;
import gov.aps.jca.cas.ProcessVariableEventCallback;
import gov.aps.jca.cas.ProcessVariableExistanceCallback;
import gov.aps.jca.cas.ProcessVariableExistanceCompletion;
import gov.aps.jca.cas.Server;
import gov.aps.jca.cas.ServerContext;

public class CANameServer
{
    public static void main(String[] args) throws Exception
    {   // Log as much as possible
        Logger logger = Logger.getLogger("");
        logger.setLevel(Level.ALL);
        for (Handler handler : logger.getHandlers())
            handler.setLevel(Level.ALL);
                
        JCALibrary jca = JCALibrary.getInstance();        
        Server server = new Server()
        {
            @Override
            public ProcessVariableExistanceCompletion processVariableExistanceTest(String name,
                                                                                   InetSocketAddress client,
                                                                                   ProcessVariableExistanceCallback callback)
                    throws CAException, IllegalArgumentException, IllegalStateException
            {
                System.out.println("Client " + client + " searches for '" + name + "'");
                // Options:
                // 1) Return DOES_NOT_EXIST_HERE, and that's the end
                // 2) Return EXISTS_HERE, in which case the library will reply with this server's IP and port,
                //    and then processVariableAttach() will be called to provide the PV
                //
                // There is no API for returning "EXISTS, but use the following IP and port",
                // as necessary for a name server.
                // The SearchResponse
                // https://github.com/epics-base/jca/blob/master/src/core/com/cosylab/epics/caj/cas/handlers/SearchResponse.java
                // always sends a reply with IP and port info from "context.getBroadcastTransport()".
                //
                // Need a CAS update which changes the ProcessVariableExistanceCompletion
                // to allow something like
                //
                //   return ProcessVariableExistanceCompletion.EXISTS(other_IP, other_port);
                return ProcessVariableExistanceCompletion.EXISTS_HERE;
            }

            @Override
            public ProcessVariable processVariableAttach(String name,
                                                         ProcessVariableEventCallback event,
                                                         ProcessVariableAttachCallback attach)
                    throws CAStatusException, IllegalArgumentException, IllegalStateException
            {
                throw new CAStatusException(CAStatus.NOSUPPORT, "not supported");
            }
        };
        
        ServerContext context = jca.createServerContext(JCALibrary.CHANNEL_ACCESS_SERVER_JAVA, server);
        context.run(0);
    }
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions