Java 类com.sun.jdi.event.VMDisconnectEvent 实例源码

项目:java-debug    文件:DebugSessionFactory.java   
public static IDebugSession getDebugSession(String projectName, String mainClass) throws Exception {
    setupProject(projectName);
    return debugSessionMap.computeIfAbsent(projectName, (name) -> {
        String projectRoot = new File(rootPath, name).getAbsolutePath();
        try {
            final IDebugSession debugSession = DebugUtility.launch(Bootstrap.virtualMachineManager(), mainClass, "", "",
                    null, new File(projectRoot, "bin").getAbsolutePath(), null, null);
            debugSession.getEventHub().events().subscribe(debugEvent -> {
                if (debugEvent.event instanceof VMDisconnectEvent) {
                    try {
                        debugSession.getEventHub().close();
                    } catch (Exception e) {
                        // do nothing.
                    }
                }
            });
            return debugSession;
        } catch (Exception ex) {
            return null;
        }
    });
}
项目:form-follows-function    文件:F3Event.java   
public static F3Event wrap(F3VirtualMachine f3vm, Event evt) {
    if (evt == null) {
        return null;
    }
    if (evt instanceof AccessWatchpointEvent) {
        return new F3AccessWatchpointEvent(f3vm, (AccessWatchpointEvent)evt);
    } else if (evt instanceof BreakpointEvent) {
        return new F3BreakpointEvent(f3vm, (BreakpointEvent)evt);
    } else if (evt instanceof ClassPrepareEvent) {
        return new F3ClassPrepareEvent(f3vm, (ClassPrepareEvent)evt);
    } else if (evt instanceof ClassUnloadEvent) {
        return new F3ClassUnloadEvent(f3vm, (ClassUnloadEvent)evt);
    } else if (evt instanceof ExceptionEvent) {
        return new F3ExceptionEvent(f3vm, (ExceptionEvent)evt);
    } else if (evt instanceof MethodEntryEvent) {
        return new F3MethodEntryEvent(f3vm, (MethodEntryEvent)evt);
    } else if (evt instanceof MethodExitEvent) {
        return new F3MethodExitEvent(f3vm, (MethodExitEvent)evt);
    } else if (evt instanceof ModificationWatchpointEvent) {
        return new F3ModificationWatchpointEvent(f3vm, (ModificationWatchpointEvent)evt);
    } else if (evt instanceof MonitorContendedEnterEvent) {
        return new F3MonitorContendedEnterEvent(f3vm, (MonitorContendedEnterEvent)evt);
    } else if (evt instanceof MonitorContendedEnteredEvent) {
        return new F3MonitorContendedEnteredEvent(f3vm, (MonitorContendedEnteredEvent)evt);
    } else if (evt instanceof MonitorWaitEvent) {
        return new F3MonitorWaitEvent(f3vm, (MonitorWaitEvent)evt);
    } else if (evt instanceof MonitorWaitedEvent) {
        return new F3MonitorWaitedEvent(f3vm, (MonitorWaitedEvent)evt);
    } else if (evt instanceof StepEvent) {
        return new F3StepEvent(f3vm, (StepEvent)evt);
    } else if (evt instanceof ThreadDeathEvent) {
        return new F3ThreadDeathEvent(f3vm, (ThreadDeathEvent)evt);
    } else if (evt instanceof ThreadStartEvent) {
        return new F3ThreadStartEvent(f3vm, (ThreadStartEvent)evt);
    } else if (evt instanceof VMDeathEvent) {
        return new F3VMDeathEvent(f3vm, (VMDeathEvent)evt);
    } else if (evt instanceof VMDisconnectEvent) {
        return new F3VMDisconnectEvent(f3vm, (VMDisconnectEvent)evt);
    } else if (evt instanceof VMStartEvent) {
        return new F3VMStartEvent(f3vm, (VMStartEvent)evt);
    } else if (evt instanceof WatchpointEvent) {
        return new F3WatchpointEvent(f3vm, (WatchpointEvent)evt);
    } else if (evt instanceof LocatableEvent) {
        return new F3LocatableEvent(f3vm, (LocatableEvent)evt);
    } else {
        return new F3Event(f3vm, evt);
    }
}
项目:gravel    文件:VMRemoteTarget.java   
private void eventLoop() throws InterruptedException {
    System.out.println("eventLoop started");
    EventQueue eventQueue = vm.eventQueue();
    boolean isRunning = true;
    while (isRunning) {
        EventSet eventSet = eventQueue.remove();
        boolean mayResume = true;
        for (Event event : eventSet) {
            System.out.println(event);
            if (event instanceof VMDeathEvent
                    || event instanceof VMDisconnectEvent) {
                isRunning = false;
            } else if (event instanceof ExceptionEvent) {
                mayResume = false;
            }
        }
        if (mayResume) eventSet.resume();
    }
}
项目:JavaTracer    文件:EventThread.java   
/**
* Dispatch incoming events
*/

   private void handleEvent(Event event) {
       if (event instanceof ExceptionEvent) {
        if (!enableProfiling)
            exceptionManager.exceptionEvent((ExceptionEvent)event);
       } else if (event instanceof MethodEntryEvent) {
        methodEntryEvent((MethodEntryEvent)event);
       } else if (event instanceof MethodExitEvent) {
        methodExitEvent((MethodExitEvent)event);
       } else if (event instanceof ThreadDeathEvent) {
           threadeath.threadDeathEvent((ThreadDeathEvent)event);
       } else if (event instanceof VMDeathEvent) {
        vmDeathEvent((VMDeathEvent)event);
       } else if (event instanceof VMDisconnectEvent) {
           connected = disconnect.vmDisconnectEvent((VMDisconnectEvent)event);
       } 
   }
项目:JavaTracer    文件:EventThread.java   
/***
* A VMDisconnectedException has happened while dealing with
* another event. We need to flush the event queue, dealing only
* with exit events (VMDeath, VMDisconnect) so that we terminate
* correctly.
*/
   synchronized void handleDisconnectedException() {
       EventQueue queue = vm.eventQueue();
       while (connected) {
           try {
               EventSet eventSet = queue.remove();
               EventIterator iter = eventSet.eventIterator();
               while (iter.hasNext()) {
                   Event event = iter.nextEvent();
                   if (event instanceof VMDeathEvent) {
                       vmDeathManager.vmDeathEvent((VMDeathEvent)event,enableProfiling);
                   } else if (event instanceof VMDisconnectEvent) {
                       connected=disconnect.vmDisconnectEvent((VMDisconnectEvent)event);
                   }
               }
               eventSet.resume(); // Resume the VM

           } catch (InterruptedException exc) {
               exc.printStackTrace();
           }
       }
   }
项目:java-debug    文件:EventHub.java   
/**
 * Gets the observable object for vm events.
 * @return      the observable object for vm events
 */
@Override
public Observable<DebugEvent> vmEvents() {
    return this.events().filter(debugEvent -> debugEvent.event instanceof VMStartEvent
            || debugEvent.event instanceof VMDisconnectEvent
            || debugEvent.event instanceof VMDeathEvent);
}
项目:form-follows-function    文件:Debugger.java   
public void vmDisconnectEvent(VMDisconnectEvent evt) {
    synchronized (listeners) {
        for (EventNotifier en : listeners) {
            en.vmDisconnectEvent(evt);
        }
    }
}
项目:jdivisitor    文件:EventThread.java   
/**
 * A {@link VMDisconnectedException} has happened while dealing with another
 * event. We need to flush the event queue, dealing only with exit events (
 * {@link VMDeatEvent} and {@link VMDisconnectEvent}) so that we terminate
 * correctly.
 */
private void handleDisconnectedException() {
    EventQueue queue = vm.eventQueue();

    while (connected) {
        try {
            EventSet eventSet = queue.remove();

            EventIterator eventIterator = eventSet.eventIterator();
            while (eventIterator.hasNext()) {
                Event event = eventIterator.nextEvent();

                if (event instanceof VMDeathEvent) {
                    handleEvent(event);
                } else if (event instanceof VMDisconnectEvent) {
                    handleEvent(event);
                    connected = false;
                }
            }
            eventSet.resume();
        } catch (InterruptedException ie) {
            vm.dispose();
            break;
        } catch (VMDisconnectedException vmde) {
            break;
        }
    }
}
项目:jive    文件:JDIEventHandler.java   
@Override
public synchronized void jdiVMDisconnect(final VMDisconnectEvent event)
{
  if (!override && !owner.isStarted())
  {
    return;
  }
  systemExit();
}
项目:jive    文件:EventHandlerLite.java   
@Override
public void jdiVMDisconnect(final VMDisconnectEvent event)
{
  //
  this.currentEvent = null;
  this.currentThread = null;
  //
  this.currentEvent = null;
  this.currentThread = null;
}
项目:jive    文件:JiveDebugTarget.java   
@Override
public void handleVMDisconnect(final VMDisconnectEvent event)
{
  if (isActive())
  {
    // this waits for all pending thread deaths to be processed
    jdiHandler().jdiVMDisconnect(event);
  }
  super.handleVMDisconnect(event);
}
项目:lookaside_java-1.8.0-openjdk    文件:FieldMonitor.java   
public static void main(String[] args)
    throws IOException, InterruptedException {

  //VirtualMachine vm = launchTarget(sb.toString());
  VirtualMachine vm = launchTarget(CLASS_NAME);

  System.out.println("Vm launched");

  // process events
  EventQueue eventQueue = vm.eventQueue();
  // resume the vm

  Process process = vm.process();


  // Copy target's output and error to our output and error.
  Thread outThread = new StreamRedirectThread("out reader", process.getInputStream());
  Thread errThread = new StreamRedirectThread("error reader", process.getErrorStream());

  errThread.start();
  outThread.start();

  boolean connected = true;
  int watched = 0;
  while (connected) {
    EventSet eventSet = eventQueue.remove();
    for (Event event : eventSet) {
      System.out.println("FieldMonitor-main receives: "+event);
      if (event instanceof VMStartEvent) {
        addClassWatch(vm);
      } else if (event instanceof VMDeathEvent
          || event instanceof VMDisconnectEvent) {
        // exit
        connected = false;
      } else if (event instanceof ClassPrepareEvent) {
        // watch field on loaded class
        System.out.println("ClassPrepareEvent");
        ClassPrepareEvent classPrepEvent = (ClassPrepareEvent) event;
        ReferenceType refType = classPrepEvent
            .referenceType();
        addFieldWatch(vm, refType);
      } else if (event instanceof ModificationWatchpointEvent) {
        watched++;
        System.out.println("sleep for 500 ms");
        Thread.sleep(500);

        ModificationWatchpointEvent modEvent = (ModificationWatchpointEvent) event;
        System.out.println("old="
            + modEvent.valueCurrent());
        System.out.println("new=" + modEvent.valueToBe());
      }
    }
    System.out.println("resume...");
    eventSet.resume();
  }
  // Shutdown begins when event thread terminates
  try {
      errThread.join(); // Make sure output is forwarded
      outThread.join();
  } catch (InterruptedException exc) {
      // we don't interrupt
  }

  if (watched != 11) { // init + 10 modifications in TestPostFieldModification class
      throw new Error("Expected to receive 11 times ModificationWatchpointEvent, but got "+watched);
  }
}
项目:form-follows-function    文件:F3VMDisconnectEvent.java   
public F3VMDisconnectEvent(F3VirtualMachine f3vm, VMDisconnectEvent underlying) {
    super(f3vm, underlying);
}
项目:form-follows-function    文件:F3VMDisconnectEvent.java   
@Override
protected VMDisconnectEvent underlying() {
    return (VMDisconnectEvent) super.underlying();
}
项目:form-follows-function    文件:EventNotifierAdapter.java   
public void vmDisconnectEvent(VMDisconnectEvent e) {
}
项目:infobip-open-jdk-8    文件:FieldMonitor.java   
public static void main(String[] args)
    throws IOException, InterruptedException {

  //VirtualMachine vm = launchTarget(sb.toString());
  VirtualMachine vm = launchTarget(CLASS_NAME);

  System.out.println("Vm launched");

  // process events
  EventQueue eventQueue = vm.eventQueue();
  // resume the vm

  Process process = vm.process();


  // Copy target's output and error to our output and error.
  Thread outThread = new StreamRedirectThread("out reader", process.getInputStream());
  Thread errThread = new StreamRedirectThread("error reader", process.getErrorStream());

  errThread.start();
  outThread.start();

  boolean connected = true;
  int watched = 0;
  while (connected) {
    EventSet eventSet = eventQueue.remove();
    for (Event event : eventSet) {
      System.out.println("FieldMonitor-main receives: "+event);
      if (event instanceof VMStartEvent) {
        addClassWatch(vm);
      } else if (event instanceof VMDeathEvent
          || event instanceof VMDisconnectEvent) {
        // exit
        connected = false;
      } else if (event instanceof ClassPrepareEvent) {
        // watch field on loaded class
        System.out.println("ClassPrepareEvent");
        ClassPrepareEvent classPrepEvent = (ClassPrepareEvent) event;
        ReferenceType refType = classPrepEvent
            .referenceType();
        addFieldWatch(vm, refType);
      } else if (event instanceof ModificationWatchpointEvent) {
        watched++;
        System.out.println("sleep for 500 ms");
        Thread.sleep(500);

        ModificationWatchpointEvent modEvent = (ModificationWatchpointEvent) event;
        System.out.println("old="
            + modEvent.valueCurrent());
        System.out.println("new=" + modEvent.valueToBe());
      }
    }
    System.out.println("resume...");
    eventSet.resume();
  }
  // Shutdown begins when event thread terminates
  try {
      errThread.join(); // Make sure output is forwarded
      outThread.join();
  } catch (InterruptedException exc) {
      // we don't interrupt
  }

  if (watched != 11) { // init + 10 modifications in TestPostFieldModification class
      throw new Error("Expected to receive 11 times ModificationWatchpointEvent, but got "+watched);
  }
}
项目:jdivisitor    文件:VisitableVMDisconnectEvent.java   
public VisitableVMDisconnectEvent(VMDisconnectEvent event) {
    this.event = event;
}
项目:jdivisitor    文件:EmptyEventVisitor.java   
@Override
public void visit(VMDisconnectEvent event) {
}
项目:gravel    文件:VMTargetStarter.java   
public VMRemoteTarget createJVM() throws IOException, InterruptedException,
        IncompatibleThreadStateException {
    Process process = startSecondJVM(VMLocalTarget.class);
    sleep(90);
    // connect
    VirtualMachine vm = new VMAcquirer().connect(debugPort);

    ClassPrepareRequest createClassPrepareRequest = vm
            .eventRequestManager().createClassPrepareRequest();
    createClassPrepareRequest.addClassFilter(VMLocalTarget.class.getName());
    createClassPrepareRequest.enable();

    vm.resume();

    List<ThreadReference> allThreads = vm.allThreads();
    for (ThreadReference threadReference : allThreads) {
        System.out.println(threadReference+" isSuspended: "+threadReference.isSuspended()+" suspendCount: "+threadReference.suspendCount());
    }

    // process events
    EventQueue eventQueue = vm.eventQueue();
    while (true) {
        EventSet eventSet = eventQueue.remove();
        for (Event event : eventSet) {
            if (event instanceof ClassPrepareEvent) {
                event.request().disable();
                installHaltPoint(vm);
            }
            if (event instanceof VMDeathEvent
                    || event instanceof VMDisconnectEvent) {
                return null;
            }
            if (event instanceof BreakpointEvent) {
                event.request().disable();
                ThreadReference thread = ((BreakpointEvent) event).thread();
                return new VMRemoteTarget(process, vm, thread, debugPort);
            }
        }
        eventSet.resume();
    }
}
项目:JavaTracer    文件:DisconnectManager.java   
public boolean vmDisconnectEvent(VMDisconnectEvent event) {
    return false;
}
项目:jdivisitor    文件:EventVisitor.java   
/**
 * Visit a {@code VMDisconnectEvent}.
 *
 * @param event Event to visit
 */
void visit(VMDisconnectEvent event);
项目:jive    文件:IJDIEventHandler.java   
/**
 * Notification of disconnection from target VM.
 */
void jdiVMDisconnect(VMDisconnectEvent event);