How to use listener method of org.openqa.selenium.grid.data.SessionClosedEvent class

Best Selenium code snippet using org.openqa.selenium.grid.data.SessionClosedEvent.listener

Source:LocalNode.java Github

copy

Full Screen

...159 .build();160 this.regularly = new Regularly("Local Node: " + externalUri);161 regularly.submit(currentSessions::cleanUp, Duration.ofSeconds(30), Duration.ofSeconds(30));162 regularly.submit(tempFileSystems::cleanUp, Duration.ofSeconds(30), Duration.ofSeconds(30));163 bus.addListener(NodeAddedEvent.listener(nodeId -> {164 if (getId().equals(nodeId)) {165 // Lets avoid to create more than one "Regularly" when the Node registers again.166 if (!heartBeatStarted.getAndSet(true)) {167 regularly.submit(168 () -> bus.fire(new NodeHeartBeatEvent(getStatus())), heartbeatPeriod, heartbeatPeriod);169 }170 }171 }));172 bus.addListener(SessionClosedEvent.listener(id -> {173 try {174 this.stop(id);175 } catch (NoSuchSessionException ignore) {176 }177 if (this.isDraining()) {178 int done = pendingSessions.decrementAndGet();179 if (done <= 0) {180 LOG.info("Firing node drain complete message");181 bus.fire(new NodeDrainComplete(this.getId()));182 }183 }184 }));185 new JMXHelper().register(this);186 }...

Full Screen

Full Screen

Source:GridModel.java Github

copy

Full Screen

...54 private final Map<Availability, Set<NodeStatus>> nodes = new ConcurrentHashMap<>();55 private final EventBus events;56 public GridModel(EventBus events, Secret registrationSecret) {57 this.events = Require.nonNull("Event bus", events);58 events.addListener(NodeDrainStarted.listener(nodeId -> setAvailability(nodeId, DRAINING)));59 events.addListener(NodeDrainComplete.listener(this::remove));60 events.addListener(NodeRemovedEvent.listener(this::remove));61 events.addListener(NodeStatusEvent.listener(status -> refresh(registrationSecret, status)));62 events.addListener(SessionClosedEvent.listener(this::release));63 }64 public GridModel add(NodeStatus node) {65 Require.nonNull("Node", node);66 Lock writeLock = lock.writeLock();67 writeLock.lock();68 try {69 // If we've already added the node, remove it.70 for (Set<NodeStatus> nodes : nodes.values()) {71 Iterator<NodeStatus> iterator = nodes.iterator();72 while (iterator.hasNext()) {73 NodeStatus next = iterator.next();74 // If the ID is the same, we're re-adding a node. If the URI is the same a node probably restarted75 if (next.getId().equals(node.getId()) || next.getUri().equals(node.getUri())) {76 LOG.info(String.format("Re-adding node with id %s and URI %s.", node.getId(), node.getUri()));...

Full Screen

Full Screen

Source:LocalSessionMap.java Github

copy

Full Screen

1// Licensed to the Software Freedom Conservancy (SFC) under one2// or more contributor license agreements. See the NOTICE file3// distributed with this work for additional information4// regarding copyright ownership. The SFC licenses this file5// to you under the Apache License, Version 2.0 (the6// "License"); you may not use this file except in compliance7// with the License. You may obtain a copy of the License at8//9// http://www.apache.org/licenses/LICENSE-2.010//11// Unless required by applicable law or agreed to in writing,12// software distributed under the License is distributed on an13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY14// KIND, either express or implied. See the License for the15// specific language governing permissions and limitations16// under the License.17package org.openqa.selenium.grid.sessionmap.local;18import static org.openqa.selenium.grid.data.SessionClosedEvent.SESSION_CLOSED;19import org.openqa.selenium.NoSuchSessionException;20import org.openqa.selenium.events.EventBus;21import org.openqa.selenium.grid.data.Session;22import org.openqa.selenium.grid.data.SessionClosedEvent;23import org.openqa.selenium.grid.sessionmap.SessionMap;24import org.openqa.selenium.remote.SessionId;25import org.openqa.selenium.remote.tracing.DistributedTracer;26import org.openqa.selenium.remote.tracing.Span;27import java.util.HashMap;28import java.util.Map;29import java.util.Objects;30import java.util.concurrent.locks.Lock;31import java.util.concurrent.locks.ReadWriteLock;32import java.util.concurrent.locks.ReentrantReadWriteLock;33public class LocalSessionMap extends SessionMap {34 private final DistributedTracer tracer;35 private final EventBus bus;36 private final Map<SessionId, Session> knownSessions = new HashMap<>();37 private final ReadWriteLock lock = new ReentrantReadWriteLock(/* be fair */ true);38 public LocalSessionMap(DistributedTracer tracer, EventBus bus) {39 this.tracer = Objects.requireNonNull(tracer);40 this.bus = Objects.requireNonNull(bus);41 bus.addListener(SESSION_CLOSED, event -> {42 SessionId id = event.getData(SessionId.class);43 knownSessions.remove(id);44 });45 }46 @Override47 public boolean add(Session session) {48 Objects.requireNonNull(session, "Session has not been set");49 try (Span span = tracer.createSpan("sessionmap.add", tracer.getActiveSpan())) {50 span.addTag("session.id", session.getId());51 span.addTag("session.capabilities", session.getCapabilities());52 span.addTag("session.uri", session.getUri());53 Lock writeLock = lock.writeLock();54 writeLock.lock();55 try {56 knownSessions.put(session.getId(), session);57 } finally {58 writeLock.unlock();59 }60 return true;61 }62 }63 @Override64 public Session get(SessionId id) {65 Objects.requireNonNull(id, "Session ID has not been set");66 try (Span span = tracer.createSpan("sessionmap.get", tracer.getActiveSpan())) {67 span.addTag("session.id", id);68 Lock readLock = lock.readLock();69 readLock.lock();70 try {71 Session session = knownSessions.get(id);72 if (session == null) {73 throw new NoSuchSessionException("Unable to find session with ID: " + id);74 }75 span.addTag("session.capabilities", session.getCapabilities());76 span.addTag("session.uri", session.getUri());77 return session;78 } finally {79 readLock.unlock();80 }81 }82 }83 @Override84 public void remove(SessionId id) {85 Objects.requireNonNull(id, "Session ID has not been set");86 try (Span span = tracer.createSpan("sessionmap.remove", tracer.getActiveSpan())) {87 span.addTag("session.id", id);88 Lock writeLock = lock.writeLock();89 writeLock.lock();90 try {91 knownSessions.remove(id);92 } finally {93 writeLock.unlock();94 }95 }96 }97}...

Full Screen

Full Screen

Source:SessionClosedEvent.java Github

copy

Full Screen

...25 private static final EventName SESSION_CLOSED = new EventName("session-closed");26 public SessionClosedEvent(SessionId id) {27 super(SESSION_CLOSED, id);28 }29 public static EventListener<SessionId> listener(Consumer<SessionId> handler) {30 Require.nonNull("Handler", handler);31 return new EventListener<>(SESSION_CLOSED, SessionId.class, handler);32 }33}...

Full Screen

Full Screen

listener

Using AI Code Generation

copy

Full Screen

1public class SessionClosedEventListener implements SessionClosedEvent.Listener {2 public void sessionClosed(SessionClosedEvent event) {3 System.out.println(event.getSessionId());4 }5}6config.add(new SessionClosedEventListener());7config.get(SessionClosedEvent.Listener.class)8config.get(SessionClosedEvent.Listener.class, SessionClosedEventListener.class)9config.get(SessionClosedEvent.Listener.class, "listener name")10config.get(SessionClosedEvent.Listener.class, "listener name", SessionClosedEventListener.class)11config.remove(SessionClosedEvent.Listener.class)12config.remove(SessionClosedEvent.Listener.class, SessionClosedEventListener.class)13config.remove(SessionClosedEvent.Listener.class, "listener name")14config.remove(SessionClosedEvent.Listener.class, "listener name", SessionClosedEventListener.class)15config.remove(SessionClosedEvent.Listener.class, "listener name", SessionClosedEventListener.class)16config.remove(SessionClosedEvent.Listener.class, "listener name", SessionClosedEventListener.class)17config.remove(SessionClosedEvent.Listener.class, "listener name", SessionClosedEventListener.class)18config.remove(SessionClosedEvent.Listener.class, "listener name", SessionClosedEventListener.class)19config.remove(SessionClosedEvent.Listener.class, "listener name", SessionClosedEventListener.class)20config.remove(SessionClosedEvent.Listener.class, "listener name", SessionClosedEventListener.class)21config.remove(SessionClosedEvent.Listener.class, "listener name", SessionClosedEventListener.class)22config.remove(Session

Full Screen

Full Screen

Selenium 4 Tutorial:

LambdaTest’s Selenium 4 tutorial is covering every aspects of Selenium 4 testing with examples and best practices. Here you will learn basics, such as how to upgrade from Selenium 3 to Selenium 4, to some advanced concepts, such as Relative locators and Selenium Grid 4 for Distributed testing. Also will learn new features of Selenium 4, such as capturing screenshots of specific elements, opening a new tab or window on the browser, and new protocol adoptions.

Chapters:

  1. Upgrading From Selenium 3 To Selenium 4?: In this chapter, learn in detail how to update Selenium 3 to Selenium 4 for Java binding. Also, learn how to upgrade while using different build tools such as Maven or Gradle and get comprehensive guidance for upgrading Selenium.

  2. What’s New In Selenium 4 & What’s Being Deprecated? : Get all information about new implementations in Selenium 4, such as W3S protocol adaption, Optimized Selenium Grid, and Enhanced Selenium IDE. Also, learn what is deprecated for Selenium 4, such as DesiredCapabilites and FindsBy methods, etc.

  3. Selenium 4 With Python: Selenium supports all major languages, such as Python, C#, Ruby, and JavaScript. In this chapter, learn how to install Selenium 4 for Python and the features of Python in Selenium 4, such as Relative locators, Browser manipulation, and Chrom DevTool protocol.

  4. Selenium 4 Is Now W3C Compliant: JSON Wireframe protocol is retiring from Selenium 4, and they are adopting W3C protocol to learn in detail about the advantages and impact of these changes.

  5. How To Use Selenium 4 Relative Locator? : Selenium 4 came with new features such as Relative Locators that allow constructing locators with reference and easily located constructors nearby. Get to know its different use cases with examples.

  6. Selenium Grid 4 Tutorial For Distributed Testing: Selenium Grid 4 allows you to perform tests over different browsers, OS, and device combinations. It also enables parallel execution browser testing, reads up on various features of Selenium Grid 4 and how to download it, and runs a test on Selenium Grid 4 with best practices.

  7. Selenium Video Tutorials: Binge on video tutorials on Selenium by industry experts to get step-by-step direction from automating basic to complex test scenarios with Selenium.

Selenium 101 certifications:

LambdaTest also provides certification for Selenium testing to accelerate your career in Selenium automation testing.

Run Selenium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in SessionClosedEvent

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful