当前位置: 首页>>代码示例>>Java>>正文


Java DatabaseReference.removeEventListener方法代码示例

本文整理汇总了Java中com.google.firebase.database.DatabaseReference.removeEventListener方法的典型用法代码示例。如果您正苦于以下问题:Java DatabaseReference.removeEventListener方法的具体用法?Java DatabaseReference.removeEventListener怎么用?Java DatabaseReference.removeEventListener使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.firebase.database.DatabaseReference的用法示例。


在下文中一共展示了DatabaseReference.removeEventListener方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testSubscribeThenUnsubscribeWithoutProblems

import com.google.firebase.database.DatabaseReference; //导入方法依赖的package包/类
@Test
public void testSubscribeThenUnsubscribeWithoutProblems()
    throws InterruptedException {
  DatabaseReference ref = IntegrationTestUtils.getRandomNode(masterApp) ;

  ValueEventListener listener =
      new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot snapshot) {}

        @Override
        public void onCancelled(DatabaseError error) {
          fail("Should not be cancelled");
        }
      };

  ValueEventListener listenerHandle = ref.addValueEventListener(listener);
  ZombieVerifier.verifyRepoZombies(ref);
  ref.removeEventListener(listenerHandle);
  ZombieVerifier.verifyRepoZombies(ref);
  ValueEventListener listenerHandle2 = ref.addValueEventListener(listener);
  ZombieVerifier.verifyRepoZombies(ref);
  ref.removeEventListener(listenerHandle2);
  ZombieVerifier.verifyRepoZombies(ref);
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:26,代码来源:EventTestIT.java

示例2: testSubscribeThenUnsubscribeWithoutProblemsWithLimit

import com.google.firebase.database.DatabaseReference; //导入方法依赖的package包/类
@Test
public void testSubscribeThenUnsubscribeWithoutProblemsWithLimit()
    throws InterruptedException {
  DatabaseReference ref = IntegrationTestUtils.getRandomNode(masterApp) ;

  ValueEventListener listener =
      new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot snapshot) {}

        @Override
        public void onCancelled(DatabaseError error) {
          fail("Should not be cancelled");
        }
      };

  ValueEventListener listenerHandle = ref.limitToLast(100).addValueEventListener(listener);
  ZombieVerifier.verifyRepoZombies(ref);
  ref.removeEventListener(listenerHandle);
  ZombieVerifier.verifyRepoZombies(ref);
  ValueEventListener listenerHandle2 = ref.limitToLast(100).addValueEventListener(listener);
  ZombieVerifier.verifyRepoZombies(ref);
  ref.removeEventListener(listenerHandle2);
  ZombieVerifier.verifyRepoZombies(ref);
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:26,代码来源:EventTestIT.java

示例3: testUnregisterSameCallbackTooManyTimes

import com.google.firebase.database.DatabaseReference; //导入方法依赖的package包/类
@Test
public void testUnregisterSameCallbackTooManyTimes()
    throws InterruptedException {
  DatabaseReference ref = IntegrationTestUtils.getRandomNode(masterApp) ;

  ValueEventListener listener =
      ref.addValueEventListener(
          new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot snapshot) {
              // no-op
            }

            @Override
            public void onCancelled(DatabaseError error) {
              // no-op
            }
          });

  ZombieVerifier.verifyRepoZombies(ref);

  ref.removeEventListener(listener);
  ref.removeEventListener(listener);
  ZombieVerifier.verifyRepoZombies(ref);
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:26,代码来源:EventTestIT.java

示例4: getBookFromIdInList

import com.google.firebase.database.DatabaseReference; //导入方法依赖的package包/类
public void getBookFromIdInList(@BOOK_LISTS String currentList, String bookId,
                                final GetBookFromListListener bookListener) {
  final DatabaseReference reference = database.getReference()
      .child(currentUser.getUid())
      .child(currentList)
      .child(bookId);

  final ValueEventListener valueEventListener = new ValueEventListener() {
    @Override
    public void onDataChange(DataSnapshot dataSnapshot) {
      bookListener.onReceivedBook(dataSnapshot.getValue(Book.class));
      reference.removeEventListener(this);
    }

    @Override
    public void onCancelled(DatabaseError databaseError) {
      bookListener.onError();
      reference.removeEventListener(this);
    }
  };

  reference.addValueEventListener(valueEventListener);

}
 
开发者ID:paulnunezm,项目名称:Boookito-Capstone-Project,代码行数:25,代码来源:FirebaseRepo.java

示例5: closeAllActiveListeners

import com.google.firebase.database.DatabaseReference; //导入方法依赖的package包/类
public void closeAllActiveListeners() {
    for (ValueEventListener listener : activeListeners.keySet()) {
        DatabaseReference reference = activeListeners.get(listener);
        reference.removeEventListener(listener);
    }

    activeListeners.clear();
}
 
开发者ID:rozdoum,项目名称:social-app-android,代码行数:9,代码来源:DatabaseHelper.java

示例6: testQueriesOnLeafNodes

import com.google.firebase.database.DatabaseReference; //导入方法依赖的package包/类
@Test
public void testQueriesOnLeafNodes()
    throws InterruptedException, ExecutionException, TestFailure, TimeoutException {
  DatabaseReference ref = IntegrationTestUtils.getRandomNode(masterApp) ;
  final Semaphore semaphore = new Semaphore(0);
  new WriteFuture(ref, "leaf-node").timedGet();

  final List<DataSnapshot> snapshots = new ArrayList<>();
  Query query = ref.orderByChild("foo").limitToLast(1);
  final ValueEventListener listener =
      query.addValueEventListener(
          new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot snapshot) {
              snapshots.add(snapshot);
              semaphore.release();
            }

            @Override
            public void onCancelled(DatabaseError error) {
              Assert.fail();
            }
          });

  TestHelpers.waitFor(semaphore);

  Assert.assertEquals(1, snapshots.size());
  Assert.assertNull(snapshots.get(0).getValue());

  // cleanup
  TestHelpers.waitForRoundtrip(ref);
  ref.removeEventListener(listener);
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:34,代码来源:OrderByTestIT.java

示例7: testServerRespectsKeyIndex

import com.google.firebase.database.DatabaseReference; //导入方法依赖的package包/类
@Test
public void testServerRespectsKeyIndex()
    throws InterruptedException, ExecutionException, TimeoutException, TestFailure {
  List<DatabaseReference> refs = IntegrationTestUtils.getRandomNode(masterApp, 2);
  DatabaseReference writer = refs.get(0);
  DatabaseReference reader = refs.get(1);

  Map<String, Object> initial = MapBuilder.of("a", 1, "b", 2, "c", 3);
  // If the server doesn't respect the index, it will send down limited data, but with no
  // offset, so the expected and actual data don't match.
  Query query = reader.orderByKey().startAt("b").limitToFirst(2);

  new WriteFuture(writer, initial).timedGet();

  final List<String> actualChildren = new ArrayList<>();
  final Semaphore semaphore = new Semaphore(0);
  ValueEventListener valueListener =
      query.addValueEventListener(
          new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot snapshot) {
              for (DataSnapshot child : snapshot.getChildren()) {
                actualChildren.add(child.getKey());
              }
              semaphore.release();
            }

            @Override
            public void onCancelled(DatabaseError error) {
              Assert.fail();
            }
          });

  TestHelpers.waitFor(semaphore);
  Assert.assertEquals(ImmutableList.of("b", "c"), actualChildren);

  // cleanup
  reader.removeEventListener(valueListener);
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:40,代码来源:OrderByTestIT.java

示例8: testRemovingDefaultListener

import com.google.firebase.database.DatabaseReference; //导入方法依赖的package包/类
@Test
public void testRemovingDefaultListener()
    throws InterruptedException, ExecutionException, TimeoutException, TestFailure, IOException {
  DatabaseReference ref = IntegrationTestUtils.getRandomNode(masterApp) ;

  Object initialData = MapBuilder.of("key", "value");
  new WriteFuture(ref, initialData).timedGet();

  ValueEventListener listener =
      ref.orderByKey()
          .addValueEventListener(
              new ValueEventListener() {
                @Override
                public void onDataChange(DataSnapshot snapshot) {}

                @Override
                public void onCancelled(DatabaseError error) {}
              });

  ref.addValueEventListener(listener);
  // Should remove both listener and should remove the listen sent to the server
  ref.removeEventListener(listener);

  // This used to crash because a listener for ref.orderByKey() existed already
  Object result = new ReadFuture(ref.orderByKey()).waitForLastValue();
  assertEquals(initialData, result);
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:28,代码来源:OrderByTestIT.java

示例9: testRemoveListenerOnDefaultQuery

import com.google.firebase.database.DatabaseReference; //导入方法依赖的package包/类
@Test
public void testRemoveListenerOnDefaultQuery()
    throws InterruptedException, ExecutionException, TimeoutException, TestFailure {
  DatabaseReference ref = IntegrationTestUtils.getRandomNode(masterApp);
  new WriteFuture(ref.child("a"), "foo", 100).timedGet();

  final Semaphore semaphore = new Semaphore(0);
  final DataSnapshot[] snapshotHolder = new DataSnapshot[1];

  ValueEventListener listener = ref.startAt(99).addValueEventListener(new ValueEventListener() {
    @Override
    public void onDataChange(DataSnapshot snapshot) {
      snapshotHolder[0] = snapshot;
      semaphore.release();
    }

    @Override
    public void onCancelled(DatabaseError error) {
      fail("Unexpected error: " + error);
    }
  });

  TestHelpers.waitFor(semaphore);
  Map<String, Object> expected = MapBuilder.of("a", "foo");
  TestHelpers.assertDeepEquals(expected, snapshotHolder[0].getValue());

  ref.removeEventListener(listener);

  new WriteFuture(ref.child("a"), "bar", 100).timedGet();
  // the listener is removed the value should have not changed
  TestHelpers.assertDeepEquals(expected, snapshotHolder[0].getValue());
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:33,代码来源:QueryTestIT.java

示例10: breakCombo

import com.google.firebase.database.DatabaseReference; //导入方法依赖的package包/类
/** Remove the saved listener from the saved ref.*/
public void breakCombo(){
    DatabaseReference comboRef = FirebaseDatabase.getInstance().getReferenceFromUrl(ref);

    listener.killEvent();

    if (listener.getType() == FirebaseGeneralEvent.ChildEvent)
    {
        comboRef.removeEventListener((ChildEventListener) listener);
    }
    else if (listener.getType() == FirebaseGeneralEvent.ValueEvent)
    {
        comboRef.removeEventListener((ValueEventListener) listener);
    }
}
 
开发者ID:MobileDev418,项目名称:AndroidBackendlessChat,代码行数:16,代码来源:FirebaseEventCombo.java

示例11: onConnect

import com.google.firebase.database.DatabaseReference; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void onConnect(final ConnectedListener listener)
{
    DatabaseReference ref = FirebaseDatabase.getInstance().getReference(".info/connected");
    if (connectionValueListener == null && listener != null) {
        connectionValueListener = new ConnectionValueListener();
        ref.addValueEventListener(connectionValueListener);
    } else if (connectionValueListener != null && listener == null) {
        ref.removeEventListener(connectionValueListener);
        connectionValueListener = null;
    }
    connectedListener = listener;
}
 
开发者ID:mk-5,项目名称:gdx-fireapp,代码行数:17,代码来源:Database.java

示例12: testUseFallbackThenDefineIndex

import com.google.firebase.database.DatabaseReference; //导入方法依赖的package包/类
@Test
public void testUseFallbackThenDefineIndex()
    throws InterruptedException, ExecutionException, TimeoutException, TestFailure, IOException {

  DatabaseReference writer = IntegrationTestUtils.getRandomNode(masterApp) ;
  DatabaseReference readerReference = FirebaseDatabase.getInstance(masterApp).getReference();
  DatabaseReference reader = readerReference.child(writer.getPath().toString());

  Map<String, Object> foo1 =
      TestHelpers.fromJsonString(
          "{ "
              + "\"a\": {\"order\": 2, \"foo\": 1}, "
              + "\"b\": {\"order\": 0}, "
              + "\"c\": {\"order\": 1, \"foo\": false}, "
              + "\"d\": {\"order\": 3, \"foo\": \"hello\"} }");

  new WriteFuture(writer, foo1).timedGet();

  final List<DataSnapshot> snapshots = new ArrayList<>();
  final Semaphore semaphore = new Semaphore(0);
  Query query = reader.orderByChild("order").limitToLast(2);
  final ValueEventListener listener =
      query.addValueEventListener(
          new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot snapshot) {
              snapshots.add(snapshot);
              semaphore.release();
            }

            @Override
            public void onCancelled(DatabaseError error) {
              Assert.fail();
            }
          });

  TestHelpers.waitFor(semaphore);

  Assert.assertEquals(1, snapshots.size());
  Map<String, Object> expected = MapBuilder.of(
      "d", MapBuilder.of("order", 3L, "foo", "hello"),
      "a", MapBuilder.of("order", 2L, "foo", 1L));
  Assert.assertEquals(expected, snapshots.get(0).getValue());

  uploadRules(masterApp, formatRules(reader, "{ \".indexOn\": \"order\" }"));

  Map<String, Object> fooE = TestHelpers.fromJsonString("{\"order\": 1.5, \"foo\": true}");
  new WriteFuture(writer.child("e"), fooE).timedGet();
  TestHelpers.waitForRoundtrip(reader);

  Map<String, Object> fooF =
      TestHelpers.fromJsonString("{\"order\": 4, \"foo\": {\"bar\": \"baz\"}}");
  new WriteFuture(writer.child("f"), fooF).timedGet();
  TestHelpers.waitForRoundtrip(reader);

  TestHelpers.waitFor(semaphore);
  Assert.assertEquals(2, snapshots.size());

  Map<String, Object> expected2 =
      new MapBuilder()
          .put(
              "f",
              new MapBuilder()
                  .put("order", 4L)
                  .put("foo", MapBuilder.of("bar", "baz"))
                  .build())
          .put("d", MapBuilder.of("order", 3L, "foo", "hello"))
          .build();
  Assert.assertEquals(expected2, snapshots.get(1).getValue());

  // cleanup
  TestHelpers.waitForRoundtrip(reader);
  reader.removeEventListener(listener);
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:75,代码来源:OrderByTestIT.java

示例13: testUpdatesForUnindexedQuery

import com.google.firebase.database.DatabaseReference; //导入方法依赖的package包/类
@Test
public void testUpdatesForUnindexedQuery()
    throws InterruptedException, ExecutionException, TestFailure, TimeoutException {
  List<DatabaseReference> refs = IntegrationTestUtils.getRandomNode(masterApp, 2);
  final DatabaseReference reader = refs.get(0);
  final DatabaseReference writer = refs.get(1);

  final List<DataSnapshot> snapshots = new ArrayList<>();

  Map<String, Object> value = new HashMap<>();
  value.put("one", new MapBuilder().put("index", 1).put("value", "one").build());
  value.put("two", new MapBuilder().put("index", 2).put("value", "two").build());
  value.put("three", new MapBuilder().put("index", 3).put("value", "three").build());

  new WriteFuture(writer, value).timedGet();

  final Semaphore semaphore = new Semaphore(0);

  Query query = reader.orderByChild("index").limitToLast(2);
  final ValueEventListener listener =
      query.addValueEventListener(
          new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot snapshot) {
              snapshots.add(snapshot);
              semaphore.release();
            }

            @Override
            public void onCancelled(DatabaseError error) {
              Assert.fail();
            }
          });

  TestHelpers.waitFor(semaphore);

  Assert.assertEquals(1, snapshots.size());

  Map<String, Object> expected1 = new HashMap<>();
  expected1.put("two", new MapBuilder().put("index", 2L).put("value", "two").build());
  expected1.put("three", new MapBuilder().put("index", 3L).put("value", "three").build());
  Assert.assertEquals(expected1, snapshots.get(0).getValue());

  // update child which should trigger value event
  writer.child("one/index").setValueAsync(4);
  TestHelpers.waitFor(semaphore);

  Assert.assertEquals(2, snapshots.size());
  Map<String, Object> expected2 = new HashMap<>();
  expected2.put("three", new MapBuilder().put("index", 3L).put("value", "three").build());
  expected2.put("one", new MapBuilder().put("index", 4L).put("value", "one").build());
  Assert.assertEquals(expected2, snapshots.get(1).getValue());

  // cleanup
  TestHelpers.waitForRoundtrip(reader);
  reader.removeEventListener(listener);
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:58,代码来源:OrderByTestIT.java

示例14: testServerRespectsValueIndex

import com.google.firebase.database.DatabaseReference; //导入方法依赖的package包/类
@Test
public void testServerRespectsValueIndex()
    throws InterruptedException, ExecutionException, TimeoutException, TestFailure, IOException {
  List<DatabaseReference> refs = IntegrationTestUtils.getRandomNode(masterApp, 2);
  DatabaseReference writer = refs.get(0);
  DatabaseReference reader = refs.get(1);

  final String indexRule = "{ \".indexOn\": \".value\"}";
  String rules = formatRules(writer, indexRule);

  uploadRules(masterApp, rules);

  Map<String, Object> initial = MapBuilder.of("a", 1, "c", 2, "b", 3);
  // If the server doesn't respect the index, it will send down limited data, but with no
  // offset, so the expected and actual data don't match.
  Query query = reader.orderByValue().startAt(2).limitToFirst(2);

  new WriteFuture(writer, initial).timedGet();

  final List<String> actualChildren = new ArrayList<>();
  final Semaphore semaphore = new Semaphore(0);
  ValueEventListener valueListener =
      query.addValueEventListener(
          new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot snapshot) {
              for (DataSnapshot child : snapshot.getChildren()) {
                actualChildren.add(child.getKey());
              }
              semaphore.release();
            }

            @Override
            public void onCancelled(DatabaseError error) {
              Assert.fail();
            }
          });

  TestHelpers.waitFor(semaphore);

  Assert.assertEquals(ImmutableList.of("c", "b"), actualChildren);

  // cleanup
  reader.removeEventListener(valueListener);
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:46,代码来源:OrderByTestIT.java

示例15: testUnsubscribeEventsAndConfirmEventsNoLongerFire

import com.google.firebase.database.DatabaseReference; //导入方法依赖的package包/类
@Test
public void testUnsubscribeEventsAndConfirmEventsNoLongerFire()
    throws TestFailure, ExecutionException, TimeoutException,
        InterruptedException {
  DatabaseReference ref = IntegrationTestUtils.getRandomNode(masterApp) ;

  final AtomicInteger callbackCount = new AtomicInteger(0);

  final ValueEventListener listener =
      ref.addValueEventListener(
          new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot snapshot) {
              if (snapshot.getValue() != null) {
                callbackCount.incrementAndGet();
              }
            }

            @Override
            public void onCancelled(DatabaseError error) {
              fail("Should not be cancelled");
            }
          });
  ZombieVerifier.verifyRepoZombies(ref);

  for (int i = 0; i < 3; ++i) {
    ref.setValueAsync(i);
  }

  TestHelpers.waitForRoundtrip(ref);
  ref.removeEventListener(listener);
  ZombieVerifier.verifyRepoZombies(ref);

  for (int i = 10; i < 13; ++i) {
    ref.setValueAsync(i);
  }

  for (int i = 20; i < 22; ++i) {
    ref.setValueAsync(i);
  }
  new WriteFuture(ref, 22).timedGet();
  assertEquals(3, callbackCount.get());
}
 
开发者ID:firebase,项目名称:firebase-admin-java,代码行数:44,代码来源:EventTestIT.java


注:本文中的com.google.firebase.database.DatabaseReference.removeEventListener方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。