ChannelFinder / cfNameserver

An EPICS pvAccess name server using ChannelFinder and recsync info
0 stars 1 forks source link

Channelfinder-based name server for Channel Access? #2

Open kasemir opened 3 weeks ago

kasemir commented 3 weeks ago

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);
    }
}
kasemir commented 3 weeks ago

Checked https://gitlab.aquenos.com/oss/epics/epics-jackie/ as an alternate Java implementation of CA. It only offers a client, no server. Updating CAJ to a more flexible ProcessVariableExistanceCompletion doesn't seem too hard if we're indeed interested in a CA name server.

kasemir commented 2 weeks ago

https://github.com/epics-base/jca/pull/80

kasemir commented 2 weeks ago

With https://github.com/epics-base/jca/pull/81 CAJ can now be used to implement a Channel Access name server for both UDP and TCP clients, https://github.com/epics-base/jca/blob/3733444f297ce673a99652f22c057e1b1dd03898/test/com/cosylab/epics/caj/cas/test/CANameServer.java

kasemir commented 4 days ago

Notes from July 3, 2024 online meeting: This GitHub repo can contain sources for both a PVA and CA name server, but they should be available as separate tools and run as separate processes. So there'll be one CA name server and one PVA name server tool, and you can run one, the other, or both.