Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Channelfinder-based name server for Channel Access? #2

Open
kasemir opened this issue Jun 13, 2024 · 4 comments
Open

Channelfinder-based name server for Channel Access? #2

kasemir opened this issue Jun 13, 2024 · 4 comments
Assignees

Comments

@kasemir
Copy link

kasemir commented Jun 13, 2024

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
Copy link
Author

kasemir commented Jun 13, 2024

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 kasemir self-assigned this Jun 14, 2024
@kasemir
Copy link
Author

kasemir commented Jun 17, 2024

epics-base/jca#80

@kasemir
Copy link
Author

kasemir commented Jun 18, 2024

With epics-base/jca#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
Copy link
Author

kasemir commented Jul 3, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant