This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 249950
Collapse All | Expand All

(-)a/remotefs.versioning/nbproject/project.xml (+8 lines)
Lines 80-85 Link Here
80
                    </run-dependency>
80
                    </run-dependency>
81
                </dependency>
81
                </dependency>
82
                <dependency>
82
                <dependency>
83
                    <code-name-base>org.openide.util</code-name-base>
84
                    <build-prerequisite/>
85
                    <compile-dependency/>
86
                    <run-dependency>
87
                        <specification-version>9.3</specification-version>
88
                    </run-dependency>
89
                </dependency>
90
                <dependency>
83
                    <code-name-base>org.openide.util.lookup</code-name-base>
91
                    <code-name-base>org.openide.util.lookup</code-name-base>
84
                    <build-prerequisite/>
92
                    <build-prerequisite/>
85
                    <compile-dependency/>
93
                    <compile-dependency/>
(-)a/remotefs.versioning/src/org/netbeans/modules/remotefs/versioning/impl/RemoteFileSystemConnectionManagerImpl.java (+97 lines)
Lines 42-49 Link Here
42
package org.netbeans.modules.remotefs.versioning.impl;
42
package org.netbeans.modules.remotefs.versioning.impl;
43
43
44
import java.util.ArrayList;
44
import java.util.ArrayList;
45
import java.util.HashMap;
45
import java.util.HashSet;
46
import java.util.HashSet;
46
import java.util.List;
47
import java.util.List;
48
import java.util.Map;
47
import java.util.Set;
49
import java.util.Set;
48
import org.netbeans.modules.nativeexecution.api.ExecutionEnvironment;
50
import org.netbeans.modules.nativeexecution.api.ExecutionEnvironment;
49
import org.netbeans.modules.nativeexecution.api.util.ConnectionListener;
51
import org.netbeans.modules.nativeexecution.api.util.ConnectionListener;
Lines 52-57 Link Here
52
import org.netbeans.modules.remotefs.versioning.api.RemoteFileSystemConnectionListener;
54
import org.netbeans.modules.remotefs.versioning.api.RemoteFileSystemConnectionListener;
53
import org.netbeans.modules.remotefs.versioning.api.RemoteFileSystemConnectionManager;
55
import org.netbeans.modules.remotefs.versioning.api.RemoteFileSystemConnectionManager;
54
import org.openide.filesystems.FileSystem;
56
import org.openide.filesystems.FileSystem;
57
import org.openide.util.Parameters;
58
import org.openide.util.RequestProcessor;
55
import org.openide.util.lookup.ServiceProvider;
59
import org.openide.util.lookup.ServiceProvider;
56
60
57
/**
61
/**
Lines 60-67 Link Here
60
 */
64
 */
61
@ServiceProvider(service=RemoteFileSystemConnectionManager.class)
65
@ServiceProvider(service=RemoteFileSystemConnectionManager.class)
62
public class RemoteFileSystemConnectionManagerImpl extends RemoteFileSystemConnectionManager implements ConnectionListener {
66
public class RemoteFileSystemConnectionManagerImpl extends RemoteFileSystemConnectionManager implements ConnectionListener {
67
    
63
    private final Set<RemoteFileSystemConnectionListener> listeners = new HashSet<>();
68
    private final Set<RemoteFileSystemConnectionListener> listeners = new HashSet<>();
69
70
    private final RequestProcessor RP = new RequestProcessor("RemoteFileSystemConnectionManager", 10); //NOI18N
64
    
71
    
72
    private final Map<ExecutionEnvironment, ConnectionNotifier> notifiers = new HashMap<>();
73
    
74
    private enum ConnectionEvent {
75
        CONNECTED,
76
        DISCONNECTED
77
    }
78
79
    private class ConnectionNotifier implements Runnable {
80
        
81
        private final ExecutionEnvironment env;
82
83
        private ConnectionEvent eventToFire;
84
        private ConnectionEvent lastFiredEvent;
85
        private final Object lock = new Object();
86
        
87
        
88
        public ConnectionNotifier(ExecutionEnvironment env) {
89
            this.env = env;
90
        }
91
92
        public void notify(ConnectionEvent newEvent) {
93
            Parameters.notNull("newEvent", newEvent); //NOI18N
94
            synchronized (lock) {
95
                ConnectionEvent event;
96
                if (eventToFire == null) {
97
                    event = newEvent;
98
                } else {
99
                    switch (newEvent) {
100
                        case CONNECTED:
101
                            // eventToFire hasn't yet been fired, so oppopsite events destroy each other
102
                            event = (eventToFire == ConnectionEvent.DISCONNECTED) ? null : ConnectionEvent.CONNECTED;
103
                            break;
104
                        case DISCONNECTED:
105
                            // eventToFire hasn't yet been fired, so oppopsite events destroy each other
106
                            event = (eventToFire == ConnectionEvent.CONNECTED) ? null : ConnectionEvent.DISCONNECTED;
107
                            break;
108
                        default:
109
                            throw new AssertionError(newEvent.name());
110
                    }
111
                }
112
                // it seems the same event can not come twice;
113
                // but what should we do if it comes? for now we ignore the 2-nd one
114
                if (event != null && event != lastFiredEvent) {
115
                    RP.post(this);
116
                }
117
            }
118
        }
119
120
        @Override
121
        public void run() {
122
            ConnectionEvent event;
123
            synchronized (lock) {
124
                event = eventToFire;
125
                lastFiredEvent = eventToFire;
126
                eventToFire = null;
127
            }
128
            if (event != null) {
129
                switch (event) {
130
                    case CONNECTED:
131
                        fireConnected(env);
132
                        break;
133
                    case DISCONNECTED:
134
                        fireDisconnected(env);
135
                        break;
136
                    default:
137
                        throw new AssertionError(event.name());
138
                }
139
            }
140
        }
141
    }
142
143
    private ConnectionNotifier getNotifier(ExecutionEnvironment env) {
144
        synchronized (notifiers) {
145
            ConnectionNotifier notifier = notifiers.get(env);
146
            if (notifier == null) {
147
                notifier = new ConnectionNotifier(env);
148
                notifiers.put(env, notifier);
149
            }
150
            return notifier;
151
        }
152
    }
153
65
    public RemoteFileSystemConnectionManagerImpl() {
154
    public RemoteFileSystemConnectionManagerImpl() {
66
        ConnectionManager.getInstance().addConnectionListener(this);
155
        ConnectionManager.getInstance().addConnectionListener(this);
67
    }
156
    }
Lines 87-92 Link Here
87
176
88
    @Override
177
    @Override
89
    public void connected(ExecutionEnvironment env) {
178
    public void connected(ExecutionEnvironment env) {
179
        getNotifier(env).notify(ConnectionEvent.CONNECTED);
180
    }
181
    
182
    private void fireConnected(ExecutionEnvironment env) {
90
        final FileSystem fileSystem = FileSystemProvider.getFileSystem(env);
183
        final FileSystem fileSystem = FileSystemProvider.getFileSystem(env);
91
        if (fileSystem != null) {
184
        if (fileSystem != null) {
92
            List<RemoteFileSystemConnectionListener> list = new ArrayList<>();
185
            List<RemoteFileSystemConnectionListener> list = new ArrayList<>();
Lines 102-107 Link Here
102
195
103
    @Override
196
    @Override
104
    public void disconnected(ExecutionEnvironment env) {
197
    public void disconnected(ExecutionEnvironment env) {
198
        getNotifier(env).notify(ConnectionEvent.DISCONNECTED);
199
    }
200
    
201
    private void fireDisconnected(ExecutionEnvironment env) {
105
        final FileSystem fileSystem = FileSystemProvider.getFileSystem(env);
202
        final FileSystem fileSystem = FileSystemProvider.getFileSystem(env);
106
        if (fileSystem != null) {
203
        if (fileSystem != null) {
107
            List<RemoteFileSystemConnectionListener> list = new ArrayList<>();
204
            List<RemoteFileSystemConnectionListener> list = new ArrayList<>();

Return to bug 249950